catboost 1.25.1 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPLOYMENT.md +22 -15
- package/README.md +37 -27
- package/binding.gyp +5 -7
- package/build_scripts/bootstrap.js +2 -1
- package/build_scripts/out/build.js +46 -68
- package/build_scripts/out/build_model.js +1 -1
- package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
- package/build_scripts/out/ci.js +5 -5
- package/build_scripts/out/config.js +32 -18
- package/build_scripts/out/install.js +5 -3
- package/build_scripts/out/package_prepublish.js +1 -1
- package/build_scripts/out/packaging.js +1 -19
- package/build_scripts/out/run_tests.js +1 -1
- package/build_scripts/out/test.js +8 -3
- package/config.json +18 -11
- package/inc/catboost/libs/model_interface/c_api.h +349 -3
- package/lib/catboost.d.ts +65 -21
- package/package.json +4 -4
- package/src/api_helpers.cpp +100 -24
- package/src/api_helpers.h +8 -7
- package/src/api_module.cpp +1 -2
- package/src/model.cpp +483 -83
- package/src/model.h +24 -9
- package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
- package/inc/util/charset/recode_result.h +0 -9
- package/inc/util/charset/unicode_table.h +0 -123
- package/inc/util/charset/unidata.h +0 -421
- package/inc/util/charset/utf8.h +0 -384
- package/inc/util/charset/wide.h +0 -843
- package/inc/util/charset/wide_specific.h +0 -22
- package/inc/util/datetime/base.h +0 -669
- package/inc/util/datetime/constants.h +0 -7
- package/inc/util/datetime/cputimer.h +0 -124
- package/inc/util/datetime/parser.h +0 -292
- package/inc/util/datetime/systime.h +0 -47
- package/inc/util/datetime/uptime.h +0 -8
- package/inc/util/digest/city.h +0 -88
- package/inc/util/digest/fnv.h +0 -73
- package/inc/util/digest/multi.h +0 -14
- package/inc/util/digest/murmur.h +0 -57
- package/inc/util/digest/numeric.h +0 -86
- package/inc/util/digest/sequence.h +0 -48
- package/inc/util/draft/date.h +0 -129
- package/inc/util/draft/datetime.h +0 -184
- package/inc/util/draft/enum.h +0 -136
- package/inc/util/draft/holder_vector.h +0 -102
- package/inc/util/draft/ip.h +0 -131
- package/inc/util/draft/matrix.h +0 -108
- package/inc/util/draft/memory.h +0 -40
- package/inc/util/folder/dirent_win.h +0 -46
- package/inc/util/folder/dirut.h +0 -121
- package/inc/util/folder/filelist.h +0 -81
- package/inc/util/folder/fts.h +0 -108
- package/inc/util/folder/iterator.h +0 -109
- package/inc/util/folder/lstat_win.h +0 -20
- package/inc/util/folder/path.h +0 -225
- package/inc/util/folder/pathsplit.h +0 -113
- package/inc/util/folder/tempdir.h +0 -42
- package/inc/util/generic/adaptor.h +0 -134
- package/inc/util/generic/algorithm.h +0 -765
- package/inc/util/generic/array_ref.h +0 -282
- package/inc/util/generic/array_size.h +0 -24
- package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
- package/inc/util/generic/bitmap.h +0 -1115
- package/inc/util/generic/bitops.h +0 -459
- package/inc/util/generic/bt_exception.h +0 -24
- package/inc/util/generic/buffer.h +0 -232
- package/inc/util/generic/cast.h +0 -176
- package/inc/util/generic/deque.h +0 -24
- package/inc/util/generic/explicit_type.h +0 -42
- package/inc/util/generic/fastqueue.h +0 -55
- package/inc/util/generic/flags.h +0 -244
- package/inc/util/generic/function.h +0 -103
- package/inc/util/generic/fwd.h +0 -171
- package/inc/util/generic/guid.h +0 -61
- package/inc/util/generic/hash.h +0 -2032
- package/inc/util/generic/hash_primes.h +0 -140
- package/inc/util/generic/hash_set.h +0 -490
- package/inc/util/generic/hide_ptr.h +0 -3
- package/inc/util/generic/intrlist.h +0 -876
- package/inc/util/generic/is_in.h +0 -53
- package/inc/util/generic/iterator.h +0 -137
- package/inc/util/generic/iterator_range.h +0 -105
- package/inc/util/generic/lazy_value.h +0 -66
- package/inc/util/generic/list.h +0 -22
- package/inc/util/generic/map.h +0 -44
- package/inc/util/generic/mapfindptr.h +0 -60
- package/inc/util/generic/maybe.h +0 -713
- package/inc/util/generic/maybe_traits.h +0 -164
- package/inc/util/generic/mem_copy.h +0 -55
- package/inc/util/generic/noncopyable.h +0 -38
- package/inc/util/generic/object_counter.h +0 -53
- package/inc/util/generic/ptr.h +0 -1113
- package/inc/util/generic/queue.h +0 -57
- package/inc/util/generic/refcount.h +0 -162
- package/inc/util/generic/reserve.h +0 -11
- package/inc/util/generic/scope.h +0 -65
- package/inc/util/generic/serialized_enum.h +0 -406
- package/inc/util/generic/set.h +0 -42
- package/inc/util/generic/singleton.h +0 -136
- package/inc/util/generic/size_literals.h +0 -65
- package/inc/util/generic/stack.h +0 -18
- package/inc/util/generic/store_policy.h +0 -120
- package/inc/util/generic/strbase.h +0 -612
- package/inc/util/generic/strbuf.h +0 -552
- package/inc/util/generic/strfcpy.h +0 -17
- package/inc/util/generic/string.h +0 -1572
- package/inc/util/generic/string_hash.h +0 -21
- package/inc/util/generic/string_ut.h +0 -1175
- package/inc/util/generic/type_name.h +0 -34
- package/inc/util/generic/typelist.h +0 -114
- package/inc/util/generic/typetraits.h +0 -325
- package/inc/util/generic/utility.h +0 -132
- package/inc/util/generic/va_args.h +0 -400
- package/inc/util/generic/variant.h +0 -631
- package/inc/util/generic/variant_traits.h +0 -171
- package/inc/util/generic/vector.h +0 -119
- package/inc/util/generic/xrange.h +0 -258
- package/inc/util/generic/yexception.h +0 -212
- package/inc/util/generic/yexception_ut.h +0 -14
- package/inc/util/generic/ylimits.h +0 -92
- package/inc/util/generic/ymath.h +0 -206
- package/inc/util/memory/addstorage.h +0 -93
- package/inc/util/memory/alloc.h +0 -27
- package/inc/util/memory/blob.h +0 -296
- package/inc/util/memory/mmapalloc.h +0 -8
- package/inc/util/memory/pool.h +0 -432
- package/inc/util/memory/segmented_string_pool.h +0 -194
- package/inc/util/memory/segpool_alloc.h +0 -118
- package/inc/util/memory/smallobj.h +0 -141
- package/inc/util/memory/tempbuf.h +0 -111
- package/inc/util/network/address.h +0 -136
- package/inc/util/network/endpoint.h +0 -61
- package/inc/util/network/hostip.h +0 -16
- package/inc/util/network/init.h +0 -60
- package/inc/util/network/interface.h +0 -17
- package/inc/util/network/iovec.h +0 -65
- package/inc/util/network/ip.h +0 -116
- package/inc/util/network/nonblock.h +0 -8
- package/inc/util/network/pair.h +0 -9
- package/inc/util/network/poller.h +0 -58
- package/inc/util/network/pollerimpl.h +0 -707
- package/inc/util/network/sock.h +0 -608
- package/inc/util/network/socket.h +0 -421
- package/inc/util/random/common_ops.h +0 -130
- package/inc/util/random/easy.h +0 -47
- package/inc/util/random/entropy.h +0 -21
- package/inc/util/random/fast.h +0 -101
- package/inc/util/random/init_atfork.h +0 -3
- package/inc/util/random/lcg_engine.h +0 -66
- package/inc/util/random/mersenne.h +0 -46
- package/inc/util/random/mersenne32.h +0 -50
- package/inc/util/random/mersenne64.h +0 -50
- package/inc/util/random/normal.h +0 -38
- package/inc/util/random/random.h +0 -30
- package/inc/util/random/shuffle.h +0 -39
- package/inc/util/str_stl.h +0 -266
- package/inc/util/stream/aligned.h +0 -99
- package/inc/util/stream/buffer.h +0 -119
- package/inc/util/stream/buffered.h +0 -225
- package/inc/util/stream/debug.h +0 -53
- package/inc/util/stream/direct_io.h +0 -43
- package/inc/util/stream/file.h +0 -108
- package/inc/util/stream/format.h +0 -444
- package/inc/util/stream/fwd.h +0 -100
- package/inc/util/stream/hex.h +0 -8
- package/inc/util/stream/holder.h +0 -44
- package/inc/util/stream/input.h +0 -273
- package/inc/util/stream/labeled.h +0 -19
- package/inc/util/stream/length.h +0 -100
- package/inc/util/stream/mem.h +0 -255
- package/inc/util/stream/multi.h +0 -32
- package/inc/util/stream/null.h +0 -61
- package/inc/util/stream/output.h +0 -304
- package/inc/util/stream/pipe.h +0 -112
- package/inc/util/stream/printf.h +0 -25
- package/inc/util/stream/str.h +0 -207
- package/inc/util/stream/tee.h +0 -28
- package/inc/util/stream/tempbuf.h +0 -21
- package/inc/util/stream/tokenizer.h +0 -214
- package/inc/util/stream/trace.h +0 -60
- package/inc/util/stream/walk.h +0 -35
- package/inc/util/stream/zerocopy.h +0 -91
- package/inc/util/stream/zerocopy_output.h +0 -57
- package/inc/util/stream/zlib.h +0 -173
- package/inc/util/string/ascii.h +0 -236
- package/inc/util/string/builder.h +0 -39
- package/inc/util/string/cast.h +0 -347
- package/inc/util/string/cstriter.h +0 -14
- package/inc/util/string/escape.h +0 -70
- package/inc/util/string/hex.h +0 -59
- package/inc/util/string/join.h +0 -194
- package/inc/util/string/printf.h +0 -13
- package/inc/util/string/reverse.h +0 -16
- package/inc/util/string/split.h +0 -1080
- package/inc/util/string/strip.h +0 -257
- package/inc/util/string/strspn.h +0 -65
- package/inc/util/string/subst.h +0 -56
- package/inc/util/string/type.h +0 -50
- package/inc/util/string/util.h +0 -195
- package/inc/util/string/vector.h +0 -132
- package/inc/util/system/align.h +0 -50
- package/inc/util/system/atexit.h +0 -22
- package/inc/util/system/atomic.h +0 -51
- package/inc/util/system/atomic_gcc.h +0 -90
- package/inc/util/system/atomic_ops.h +0 -189
- package/inc/util/system/atomic_win.h +0 -114
- package/inc/util/system/backtrace.h +0 -39
- package/inc/util/system/byteorder.h +0 -186
- package/inc/util/system/compat.h +0 -84
- package/inc/util/system/compiler.h +0 -620
- package/inc/util/system/condvar.h +0 -71
- package/inc/util/system/context.h +0 -181
- package/inc/util/system/context_aarch64.h +0 -8
- package/inc/util/system/context_i686.h +0 -9
- package/inc/util/system/context_x86.h +0 -12
- package/inc/util/system/context_x86_64.h +0 -7
- package/inc/util/system/cpu_id.h +0 -159
- package/inc/util/system/daemon.h +0 -28
- package/inc/util/system/datetime.h +0 -98
- package/inc/util/system/defaults.h +0 -149
- package/inc/util/system/demangle.h +0 -5
- package/inc/util/system/demangle_impl.h +0 -23
- package/inc/util/system/direct_io.h +0 -71
- package/inc/util/system/dynlib.h +0 -119
- package/inc/util/system/env.h +0 -32
- package/inc/util/system/error.h +0 -95
- package/inc/util/system/event.h +0 -122
- package/inc/util/system/execpath.h +0 -17
- package/inc/util/system/fasttime.h +0 -6
- package/inc/util/system/fhandle.h +0 -27
- package/inc/util/system/file.h +0 -210
- package/inc/util/system/file_lock.h +0 -34
- package/inc/util/system/filemap.h +0 -383
- package/inc/util/system/flock.h +0 -35
- package/inc/util/system/fs.h +0 -156
- package/inc/util/system/fs_win.h +0 -29
- package/inc/util/system/fstat.h +0 -46
- package/inc/util/system/getpid.h +0 -12
- package/inc/util/system/guard.h +0 -179
- package/inc/util/system/hi_lo.h +0 -139
- package/inc/util/system/hostname.h +0 -10
- package/inc/util/system/hp_timer.h +0 -36
- package/inc/util/system/info.h +0 -12
- package/inc/util/system/interrupt_signals.h +0 -22
- package/inc/util/system/madvise.h +0 -30
- package/inc/util/system/maxlen.h +0 -32
- package/inc/util/system/mem_info.h +0 -18
- package/inc/util/system/mincore.h +0 -38
- package/inc/util/system/mktemp.h +0 -11
- package/inc/util/system/mlock.h +0 -43
- package/inc/util/system/mutex.h +0 -67
- package/inc/util/system/nice.h +0 -3
- package/inc/util/system/pipe.h +0 -90
- package/inc/util/system/platform.h +0 -246
- package/inc/util/system/progname.h +0 -13
- package/inc/util/system/protect.h +0 -25
- package/inc/util/system/rusage.h +0 -26
- package/inc/util/system/rwlock.h +0 -78
- package/inc/util/system/sanitizers.h +0 -122
- package/inc/util/system/sem.h +0 -41
- package/inc/util/system/shellcommand.h +0 -472
- package/inc/util/system/shmat.h +0 -32
- package/inc/util/system/sigset.h +0 -78
- package/inc/util/system/spin_wait.h +0 -10
- package/inc/util/system/spinlock.h +0 -121
- package/inc/util/system/src_location.h +0 -25
- package/inc/util/system/src_root.h +0 -68
- package/inc/util/system/sys_alloc.h +0 -43
- package/inc/util/system/sysstat.h +0 -52
- package/inc/util/system/tempfile.h +0 -34
- package/inc/util/system/thread.h +0 -167
- package/inc/util/system/tls.h +0 -307
- package/inc/util/system/types.h +0 -119
- package/inc/util/system/unaligned_mem.h +0 -67
- package/inc/util/system/user.h +0 -5
- package/inc/util/system/utime.h +0 -6
- package/inc/util/system/valgrind.h +0 -48
- package/inc/util/system/winint.h +0 -43
- package/inc/util/system/yassert.h +0 -121
- package/inc/util/system/yield.h +0 -4
- package/inc/util/thread/factory.h +0 -65
- package/inc/util/thread/fwd.h +0 -30
- package/inc/util/thread/lfqueue.h +0 -406
- package/inc/util/thread/lfstack.h +0 -188
- package/inc/util/thread/pool.h +0 -388
- package/inc/util/thread/singleton.h +0 -42
- package/inc/util/ysafeptr.h +0 -427
- package/inc/util/ysaveload.h +0 -700
package/inc/util/memory/pool.h
DELETED
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "alloc.h"
|
|
4
|
-
|
|
5
|
-
#include <util/system/align.h>
|
|
6
|
-
#include <util/system/yassert.h>
|
|
7
|
-
#include <util/generic/bitops.h>
|
|
8
|
-
#include <util/generic/utility.h>
|
|
9
|
-
#include <util/generic/intrlist.h>
|
|
10
|
-
#include <util/generic/strbuf.h>
|
|
11
|
-
#include <util/generic/singleton.h>
|
|
12
|
-
|
|
13
|
-
#include <new>
|
|
14
|
-
#include <string>
|
|
15
|
-
#include <utility>
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Memory pool implements a memory allocation scheme that is very fast, but
|
|
19
|
-
* limited in its usage.
|
|
20
|
-
*
|
|
21
|
-
* A common use case is when you want to allocate a bunch of small objects, and
|
|
22
|
-
* then release them all at some point of your program. Using memory pool, you
|
|
23
|
-
* can just drop them off into oblivion without calling any destructors,
|
|
24
|
-
* provided that all associated memory was allocated on the pool.
|
|
25
|
-
*/
|
|
26
|
-
class TMemoryPool {
|
|
27
|
-
private:
|
|
28
|
-
using TBlock = IAllocator::TBlock;
|
|
29
|
-
|
|
30
|
-
class TChunk: public TIntrusiveListItem<TChunk> {
|
|
31
|
-
public:
|
|
32
|
-
inline TChunk(size_t len = 0) noexcept
|
|
33
|
-
: Cur_((char*)(this + 1))
|
|
34
|
-
, Left_(len)
|
|
35
|
-
{
|
|
36
|
-
Y_ASSERT((((size_t)Cur_) % PLATFORM_DATA_ALIGN) == 0);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
inline void* Allocate(size_t len) noexcept {
|
|
40
|
-
if (Left_ >= len) {
|
|
41
|
-
char* ret = Cur_;
|
|
42
|
-
|
|
43
|
-
Cur_ += len;
|
|
44
|
-
Left_ -= len;
|
|
45
|
-
|
|
46
|
-
return ret;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return nullptr;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
inline void* Allocate(size_t len, size_t align) noexcept {
|
|
53
|
-
size_t pad = AlignUp(Cur_, align) - Cur_;
|
|
54
|
-
|
|
55
|
-
void* ret = Allocate(pad + len);
|
|
56
|
-
if (ret) {
|
|
57
|
-
return static_cast<char*>(ret) + pad;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return nullptr;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
inline size_t BlockLength() const noexcept {
|
|
64
|
-
return (Cur_ + Left_) - (char*)this;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
inline size_t Used() const noexcept {
|
|
68
|
-
return Cur_ - (const char*)this;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
inline size_t Left() const noexcept {
|
|
72
|
-
return Left_;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
inline const char* Data() const noexcept {
|
|
76
|
-
return (const char*)(this + 1);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
inline char* Data() noexcept {
|
|
80
|
-
return (char*)(this + 1);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
inline size_t DataSize() const noexcept {
|
|
84
|
-
return Cur_ - Data();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
inline void ResetChunk() noexcept {
|
|
88
|
-
size_t total = DataSize() + Left();
|
|
89
|
-
Cur_ = Data();
|
|
90
|
-
Left_ = total;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private:
|
|
94
|
-
char* Cur_;
|
|
95
|
-
size_t Left_;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
using TChunkList = TIntrusiveList<TChunk>;
|
|
99
|
-
|
|
100
|
-
public:
|
|
101
|
-
class IGrowPolicy {
|
|
102
|
-
public:
|
|
103
|
-
virtual ~IGrowPolicy() = default;
|
|
104
|
-
|
|
105
|
-
virtual size_t Next(size_t prev) const noexcept = 0;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
class TLinearGrow: public IGrowPolicy {
|
|
109
|
-
public:
|
|
110
|
-
size_t Next(size_t prev) const noexcept override {
|
|
111
|
-
return prev;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
static IGrowPolicy* Instance() noexcept;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
class TExpGrow: public IGrowPolicy {
|
|
118
|
-
public:
|
|
119
|
-
size_t Next(size_t prev) const noexcept override {
|
|
120
|
-
return prev * 2;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
static IGrowPolicy* Instance() noexcept;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
struct TOptions {
|
|
127
|
-
bool RoundUpToNextPowerOfTwo;
|
|
128
|
-
TOptions()
|
|
129
|
-
: RoundUpToNextPowerOfTwo(true)
|
|
130
|
-
{
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
inline TMemoryPool(size_t initial, IGrowPolicy* grow = TExpGrow::Instance(), IAllocator* alloc = TDefaultAllocator::Instance(), const TOptions& options = TOptions())
|
|
135
|
-
: Current_(&Empty_)
|
|
136
|
-
, BlockSize_(initial)
|
|
137
|
-
, GrowPolicy_(grow)
|
|
138
|
-
, Alloc_(alloc)
|
|
139
|
-
, Options_(options)
|
|
140
|
-
, Origin_(initial)
|
|
141
|
-
, MemoryAllocatedBeforeCurrent_(0)
|
|
142
|
-
, MemoryWasteBeforeCurrent_(0)
|
|
143
|
-
{
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
inline ~TMemoryPool() {
|
|
147
|
-
Clear();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
inline void* Allocate(size_t len) {
|
|
151
|
-
return RawAllocate(AlignUp<size_t>(len, PLATFORM_DATA_ALIGN));
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
inline void* Allocate(size_t len, size_t align) {
|
|
155
|
-
return RawAllocate(AlignUp<size_t>(len, PLATFORM_DATA_ALIGN), align);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
template <typename T>
|
|
159
|
-
inline T* Allocate() {
|
|
160
|
-
return (T*)this->Allocate(sizeof(T), alignof(T));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
template <typename T>
|
|
164
|
-
inline T* Allocate(size_t align) {
|
|
165
|
-
return (T*)this->Allocate(sizeof(T), Max(align, alignof(T)));
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
template <typename T>
|
|
169
|
-
inline T* AllocateArray(size_t count) {
|
|
170
|
-
return (T*)this->Allocate(sizeof(T) * count, alignof(T));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
template <typename T>
|
|
174
|
-
inline T* AllocateArray(size_t count, size_t align) {
|
|
175
|
-
return (T*)this->Allocate(sizeof(T) * count, Max(align, alignof(T)));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
template <typename T>
|
|
179
|
-
inline T* AllocateZeroArray(size_t count) {
|
|
180
|
-
T* ptr = AllocateArray<T>(count);
|
|
181
|
-
memset(ptr, 0, count * sizeof(T));
|
|
182
|
-
return ptr;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
template <typename T>
|
|
186
|
-
inline T* AllocateZeroArray(size_t count, size_t align) {
|
|
187
|
-
T* ptr = AllocateArray<T>(count, align);
|
|
188
|
-
memset(ptr, 0, count * sizeof(T));
|
|
189
|
-
return ptr;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
template <typename T, typename... Args>
|
|
193
|
-
inline T* New(Args&&... args) {
|
|
194
|
-
return new (Allocate<T>()) T(std::forward<Args>(args)...);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
template <typename T>
|
|
198
|
-
inline T* NewArray(size_t count) {
|
|
199
|
-
T* arr = (T*)AllocateArray<T>(count);
|
|
200
|
-
|
|
201
|
-
for (T *ptr = arr, *end = arr + count; ptr != end; ++ptr) {
|
|
202
|
-
new (ptr) T;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return arr;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
template <typename TChar>
|
|
209
|
-
inline TChar* Append(const TChar* str) {
|
|
210
|
-
return Append(str, std::char_traits<TChar>::length(str) + 1); // include terminating zero byte
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
template <typename TChar>
|
|
214
|
-
inline TChar* Append(const TChar* str, size_t len) {
|
|
215
|
-
TChar* ret = static_cast<TChar*>(Allocate(len * sizeof(TChar)));
|
|
216
|
-
|
|
217
|
-
std::char_traits<TChar>::copy(ret, str, len);
|
|
218
|
-
|
|
219
|
-
return ret;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
template <typename TChar>
|
|
223
|
-
inline TBasicStringBuf<TChar> AppendString(const TBasicStringBuf<TChar>& buf) {
|
|
224
|
-
return TBasicStringBuf<TChar>(Append(buf.data(), buf.size()), buf.size());
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
template <typename TChar>
|
|
228
|
-
inline TBasicStringBuf<TChar> AppendCString(const TBasicStringBuf<TChar>& buf) {
|
|
229
|
-
TChar* ret = static_cast<TChar*>(Allocate((buf.size() + 1) * sizeof(TChar)));
|
|
230
|
-
|
|
231
|
-
std::char_traits<TChar>::copy(ret, buf.data(), buf.size());
|
|
232
|
-
*(ret + buf.size()) = 0;
|
|
233
|
-
return TBasicStringBuf<TChar>(ret, buf.size());
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
inline size_t Available() const noexcept {
|
|
237
|
-
return Current_->Left();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
inline void Clear() noexcept {
|
|
241
|
-
DoClear(false);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
inline void ClearKeepFirstChunk() noexcept {
|
|
245
|
-
DoClear(true);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
inline size_t MemoryAllocated() const noexcept {
|
|
249
|
-
return MemoryAllocatedBeforeCurrent_ + (Current_ != &Empty_ ? Current_->Used() : 0);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
inline size_t MemoryWaste() const noexcept {
|
|
253
|
-
return MemoryWasteBeforeCurrent_ + (Current_ != &Empty_ ? Current_->Left() : 0);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
template <class TOp>
|
|
257
|
-
inline void Traverse(TOp& op) const noexcept {
|
|
258
|
-
for (TChunkList::TConstIterator i = Chunks_.Begin(); i != Chunks_.End(); ++i) {
|
|
259
|
-
op(i->Data(), i->DataSize());
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
inline IAllocator* RealAllocator() const noexcept {
|
|
264
|
-
return Alloc_;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
protected:
|
|
268
|
-
inline void* RawAllocate(size_t len) {
|
|
269
|
-
void* ret = Current_->Allocate(len);
|
|
270
|
-
|
|
271
|
-
if (ret) {
|
|
272
|
-
return ret;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
AddChunk(len);
|
|
276
|
-
|
|
277
|
-
return Current_->Allocate(len);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
inline void* RawAllocate(size_t len, size_t align) {
|
|
281
|
-
Y_ASSERT(align > 0);
|
|
282
|
-
void* ret = Current_->Allocate(len, align);
|
|
283
|
-
|
|
284
|
-
if (ret) {
|
|
285
|
-
return ret;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
AddChunk(len + align - 1);
|
|
289
|
-
|
|
290
|
-
return Current_->Allocate(len, align);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
private:
|
|
294
|
-
void AddChunk(size_t hint);
|
|
295
|
-
void DoClear(bool keepfirst) noexcept;
|
|
296
|
-
|
|
297
|
-
private:
|
|
298
|
-
TChunk Empty_;
|
|
299
|
-
TChunk* Current_;
|
|
300
|
-
size_t BlockSize_;
|
|
301
|
-
IGrowPolicy* GrowPolicy_;
|
|
302
|
-
IAllocator* Alloc_;
|
|
303
|
-
TOptions Options_;
|
|
304
|
-
TChunkList Chunks_;
|
|
305
|
-
const size_t Origin_;
|
|
306
|
-
size_t MemoryAllocatedBeforeCurrent_;
|
|
307
|
-
size_t MemoryWasteBeforeCurrent_;
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
template <typename TPool>
|
|
311
|
-
struct TPoolableBase {
|
|
312
|
-
inline void* operator new(size_t bytes, TPool& pool) {
|
|
313
|
-
return pool.Allocate(bytes);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
inline void* operator new(size_t bytes, std::align_val_t align, TPool& pool) {
|
|
317
|
-
return pool.Allocate(bytes, (size_t)align);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
inline void operator delete(void*, size_t) noexcept {
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
inline void operator delete(void*, TPool&) noexcept {
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
private:
|
|
327
|
-
inline void* operator new(size_t); // disallow default allocation
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
struct TPoolable: public TPoolableBase<TMemoryPool> {
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
class TMemoryPoolAllocator: public IAllocator {
|
|
334
|
-
public:
|
|
335
|
-
inline TMemoryPoolAllocator(TMemoryPool* pool)
|
|
336
|
-
: Pool_(pool)
|
|
337
|
-
{
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
TBlock Allocate(size_t len) override {
|
|
341
|
-
TBlock ret = {Pool_->Allocate(len), len};
|
|
342
|
-
|
|
343
|
-
return ret;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
void Release(const TBlock& block) override {
|
|
347
|
-
(void)block;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
private:
|
|
351
|
-
TMemoryPool* Pool_;
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
template <class T, class TPool>
|
|
355
|
-
class TPoolAllocBase {
|
|
356
|
-
public:
|
|
357
|
-
using pointer = T*;
|
|
358
|
-
using const_pointer = const T*;
|
|
359
|
-
using reference = T&;
|
|
360
|
-
using const_reference = const T&;
|
|
361
|
-
using size_type = size_t;
|
|
362
|
-
using difference_type = ptrdiff_t;
|
|
363
|
-
using value_type = T;
|
|
364
|
-
|
|
365
|
-
inline TPoolAllocBase(TPool* pool)
|
|
366
|
-
: Pool_(pool)
|
|
367
|
-
{
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
template <typename TOther>
|
|
371
|
-
inline TPoolAllocBase(const TPoolAllocBase<TOther, TPool>& o)
|
|
372
|
-
: Pool_(o.GetPool())
|
|
373
|
-
{
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
inline T* allocate(size_t n) {
|
|
377
|
-
return (T*)Pool_->Allocate(n * sizeof(T), alignof(T));
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
inline void deallocate(pointer /*p*/, size_t /*n*/) {
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
template <class T1>
|
|
384
|
-
struct rebind {
|
|
385
|
-
using other = TPoolAllocBase<T1, TPool>;
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
inline size_type max_size() const noexcept {
|
|
389
|
-
return size_type(-1) / sizeof(T);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
template <typename... Args>
|
|
393
|
-
inline void construct(pointer p, Args&&... args) {
|
|
394
|
-
new (p) T(std::forward<Args>(args)...);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
inline void destroy(pointer p) noexcept {
|
|
398
|
-
(void)p; /* Make MSVC happy. */
|
|
399
|
-
p->~T();
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
inline TPool* GetPool() const {
|
|
403
|
-
return Pool_;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
inline friend bool operator==(const TPoolAllocBase& l, const TPoolAllocBase& r) {
|
|
407
|
-
return l.Pool_ == r.Pool_;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
inline friend bool operator!=(const TPoolAllocBase& l, const TPoolAllocBase& r) {
|
|
411
|
-
return !(l == r);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
private:
|
|
415
|
-
TPool* Pool_;
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
template <class T>
|
|
419
|
-
using TPoolAlloc = TPoolAllocBase<T, TMemoryPool>;
|
|
420
|
-
|
|
421
|
-
// Any type since it is supposed to be rebound anyway.
|
|
422
|
-
using TPoolAllocator = TPoolAlloc<int>;
|
|
423
|
-
|
|
424
|
-
template <class T>
|
|
425
|
-
inline bool operator==(const TPoolAlloc<T>&, const TPoolAlloc<T>&) noexcept {
|
|
426
|
-
return true;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
template <class T>
|
|
430
|
-
inline bool operator!=(const TPoolAlloc<T>&, const TPoolAlloc<T>&) noexcept {
|
|
431
|
-
return false;
|
|
432
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <util/system/align.h>
|
|
4
|
-
#include <util/system/yassert.h>
|
|
5
|
-
#include <util/system/defaults.h>
|
|
6
|
-
#include <util/generic/noncopyable.h>
|
|
7
|
-
#include <util/generic/vector.h>
|
|
8
|
-
#include <util/generic/strbuf.h>
|
|
9
|
-
|
|
10
|
-
#include <memory>
|
|
11
|
-
#include <cstdio>
|
|
12
|
-
#include <cstdlib>
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
* Non-reallocated storage for the objects of POD type
|
|
16
|
-
*/
|
|
17
|
-
template <class T, class Alloc = std::allocator<T>>
|
|
18
|
-
class segmented_pool : TNonCopyable {
|
|
19
|
-
protected:
|
|
20
|
-
Alloc seg_allocator;
|
|
21
|
-
struct seg_inf {
|
|
22
|
-
T* data; // allocated chunk
|
|
23
|
-
size_t _size; // size of allocated chunk in sizeof(T)-units
|
|
24
|
-
size_t freepos; // offset to free chunk's memory in bytes
|
|
25
|
-
seg_inf()
|
|
26
|
-
: data(nullptr)
|
|
27
|
-
, _size(0)
|
|
28
|
-
, freepos(0)
|
|
29
|
-
{
|
|
30
|
-
}
|
|
31
|
-
seg_inf(T* d, size_t sz)
|
|
32
|
-
: data(d)
|
|
33
|
-
, _size(sz)
|
|
34
|
-
, freepos(0)
|
|
35
|
-
{
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
using seg_container = TVector<seg_inf>;
|
|
39
|
-
using seg_iterator = typename seg_container::iterator;
|
|
40
|
-
using seg_const_iterator = typename seg_container::const_iterator;
|
|
41
|
-
const size_t segment_size; // default size of a memory chunk in sizeof(T)-units
|
|
42
|
-
size_t last_free; // size of free memory in chunk in sizeof(T)-units
|
|
43
|
-
size_t last_ins_size; // size of memory used in chunk by the last append() in bytes
|
|
44
|
-
seg_container segs; // array of memory chunks
|
|
45
|
-
seg_iterator curseg; // a segment for the current insertion
|
|
46
|
-
const char* Name; // for debug memory usage
|
|
47
|
-
protected:
|
|
48
|
-
void check_capacity(size_t len) {
|
|
49
|
-
if (Y_UNLIKELY(!last_free || len > last_free)) {
|
|
50
|
-
if (curseg != segs.end() && curseg->freepos > 0)
|
|
51
|
-
++curseg;
|
|
52
|
-
last_free = (len > segment_size ? len : segment_size);
|
|
53
|
-
if (curseg == segs.end() || curseg->_size < last_free) {
|
|
54
|
-
segs.push_back(seg_inf(seg_allocator.allocate(last_free), last_free));
|
|
55
|
-
if (Y_UNLIKELY(Name))
|
|
56
|
-
printf("Pool \"%s\" was increased by %" PRISZT " bytes to %" PRISZT " Mb.\n", Name, last_free * sizeof(T), capacity() / 0x100000);
|
|
57
|
-
curseg = segs.end() - 1;
|
|
58
|
-
}
|
|
59
|
-
Y_ASSERT(curseg->freepos == 0);
|
|
60
|
-
Y_ASSERT(curseg->_size >= last_free);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public:
|
|
65
|
-
explicit segmented_pool(size_t segsz, const char* name = nullptr)
|
|
66
|
-
: segment_size(segsz)
|
|
67
|
-
, last_free(0)
|
|
68
|
-
, last_ins_size(0)
|
|
69
|
-
, Name(name)
|
|
70
|
-
{
|
|
71
|
-
curseg = segs.begin();
|
|
72
|
-
}
|
|
73
|
-
~segmented_pool() {
|
|
74
|
-
clear();
|
|
75
|
-
}
|
|
76
|
-
/* src - array of objects, len - count of elements in array */
|
|
77
|
-
T* append(const T* src, size_t len) {
|
|
78
|
-
check_capacity(len);
|
|
79
|
-
ui8* rv = (ui8*)curseg->data + curseg->freepos;
|
|
80
|
-
last_ins_size = sizeof(T) * len;
|
|
81
|
-
if (src)
|
|
82
|
-
memcpy(rv, src, last_ins_size);
|
|
83
|
-
curseg->freepos += last_ins_size, last_free -= len;
|
|
84
|
-
return (T*)rv;
|
|
85
|
-
}
|
|
86
|
-
T* append() {
|
|
87
|
-
T* obj = get_raw();
|
|
88
|
-
new (obj) T();
|
|
89
|
-
return obj;
|
|
90
|
-
}
|
|
91
|
-
T* get_raw() { // append(0, 1)
|
|
92
|
-
check_capacity(1);
|
|
93
|
-
ui8* rv = (ui8*)curseg->data + curseg->freepos;
|
|
94
|
-
last_ins_size = sizeof(T);
|
|
95
|
-
curseg->freepos += last_ins_size, last_free -= 1;
|
|
96
|
-
return (T*)rv;
|
|
97
|
-
}
|
|
98
|
-
size_t get_segment_size() const {
|
|
99
|
-
return segment_size;
|
|
100
|
-
}
|
|
101
|
-
bool contains(const T* ptr) const {
|
|
102
|
-
for (seg_const_iterator i = segs.begin(), ie = segs.end(); i != ie; ++i)
|
|
103
|
-
if ((char*)ptr >= (char*)i->data && (char*)ptr < (char*)i->data + i->freepos)
|
|
104
|
-
return true;
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
size_t size() const {
|
|
108
|
-
size_t r = 0;
|
|
109
|
-
for (seg_const_iterator i = segs.begin(); i != segs.end(); ++i)
|
|
110
|
-
r += i->freepos;
|
|
111
|
-
return r;
|
|
112
|
-
}
|
|
113
|
-
size_t capacity() const {
|
|
114
|
-
return segs.size() * segment_size * sizeof(T);
|
|
115
|
-
}
|
|
116
|
-
void restart() {
|
|
117
|
-
if (curseg != segs.end())
|
|
118
|
-
++curseg;
|
|
119
|
-
for (seg_iterator i = segs.begin(); i != curseg; ++i)
|
|
120
|
-
i->freepos = 0;
|
|
121
|
-
curseg = segs.begin();
|
|
122
|
-
last_free = 0;
|
|
123
|
-
last_ins_size = 0;
|
|
124
|
-
}
|
|
125
|
-
void clear() {
|
|
126
|
-
for (seg_iterator i = segs.begin(); i != segs.end(); ++i)
|
|
127
|
-
seg_allocator.deallocate(i->data, i->_size);
|
|
128
|
-
segs.clear();
|
|
129
|
-
curseg = segs.begin();
|
|
130
|
-
last_free = 0;
|
|
131
|
-
last_ins_size = 0;
|
|
132
|
-
}
|
|
133
|
-
void undo_last_append() {
|
|
134
|
-
Y_ASSERT(curseg != segs.end()); // do not use before append()
|
|
135
|
-
if (last_ins_size) {
|
|
136
|
-
Y_ASSERT(last_ins_size <= curseg->freepos);
|
|
137
|
-
curseg->freepos -= last_ins_size;
|
|
138
|
-
last_free += last_ins_size / sizeof(T);
|
|
139
|
-
last_ins_size = 0;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
void alloc_first_seg() {
|
|
143
|
-
Y_ASSERT(capacity() == 0);
|
|
144
|
-
check_capacity(segment_size);
|
|
145
|
-
Y_ASSERT(capacity() == segment_size * sizeof(T));
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
class segmented_string_pool: public segmented_pool<char> {
|
|
150
|
-
private:
|
|
151
|
-
using _Base = segmented_pool<char>;
|
|
152
|
-
|
|
153
|
-
public:
|
|
154
|
-
segmented_string_pool()
|
|
155
|
-
: segmented_string_pool(1024 * 1024)
|
|
156
|
-
{
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
explicit segmented_string_pool(size_t segsz)
|
|
160
|
-
: _Base(segsz)
|
|
161
|
-
{
|
|
162
|
-
}
|
|
163
|
-
char* append(const char* src) {
|
|
164
|
-
Y_ASSERT(src);
|
|
165
|
-
return _Base::append(src, strlen(src) + 1);
|
|
166
|
-
}
|
|
167
|
-
char* append(const char* src, size_t len) {
|
|
168
|
-
char* rv = _Base::append(nullptr, len + 1);
|
|
169
|
-
if (src)
|
|
170
|
-
memcpy(rv, src, len);
|
|
171
|
-
rv[len] = 0;
|
|
172
|
-
return rv;
|
|
173
|
-
}
|
|
174
|
-
char* Append(const TStringBuf s) {
|
|
175
|
-
return append(s.data(), s.size());
|
|
176
|
-
}
|
|
177
|
-
void align_4() {
|
|
178
|
-
size_t t = (curseg->freepos + 3) & ~3;
|
|
179
|
-
last_free -= t - curseg->freepos;
|
|
180
|
-
curseg->freepos = t;
|
|
181
|
-
}
|
|
182
|
-
char* Allocate(size_t len) {
|
|
183
|
-
return append(nullptr, len);
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
template <typename T, typename C>
|
|
188
|
-
inline T* pool_push(segmented_pool<C>& pool, const T* v) {
|
|
189
|
-
static_assert(sizeof(C) == 1, "only char type supported");
|
|
190
|
-
size_t len = SizeOf(v);
|
|
191
|
-
C* buf = pool.append(nullptr, AlignUp(len));
|
|
192
|
-
memcpy(buf, v, len);
|
|
193
|
-
return (T*)buf;
|
|
194
|
-
}
|