diff --git a/src/box/memtx_allocator.h b/src/box/memtx_allocator.h index fdddef0bf33c3235b97f81387dd2ab2a8b48edd0..38e01b3ee0cee9933b5e00450578b389fb22e483 100644 --- a/src/box/memtx_allocator.h +++ b/src/box/memtx_allocator.h @@ -59,17 +59,6 @@ struct PACKED memtx_tuple { template<class Allocator> class MemtxAllocator { public: - static void free(void *ptr, size_t size) - { - Allocator::free(ptr, size); - } - - static void *alloc(size_t size) - { - collect_garbage(); - return Allocator::alloc(size); - } - static void create() { mode = MEMTX_ENGINE_FREE; @@ -145,6 +134,17 @@ class MemtxAllocator { private: static constexpr int GC_BATCH_SIZE = 100; + static void free(void *ptr, size_t size) + { + Allocator::free(ptr, size); + } + + static void *alloc(size_t size) + { + collect_garbage(); + return Allocator::alloc(size); + } + static void immediate_free_tuple(struct memtx_tuple *memtx_tuple) { size_t size = tuple_size(&memtx_tuple->base) + diff --git a/src/box/memtx_engine.cc b/src/box/memtx_engine.cc index d8ce2014371bd884e881c644f303fa37ef1e6bbb..c0963f28271fb5b9bcf0678dbc063e042fe6ec48 100644 --- a/src/box/memtx_engine.cc +++ b/src/box/memtx_engine.cc @@ -77,35 +77,10 @@ template <class ALLOC> static inline void create_memtx_tuple_format_vtab(struct tuple_format_vtab *vtab); -void * -(*memtx_alloc)(uint32_t size); -void -(*memtx_free)(void *ptr); struct tuple * (*memtx_tuple_new_raw)(struct tuple_format *format, const char *data, const char *end, bool validate); -template <class ALLOC> -static void * -memtx_alloc_impl(uint32_t size) -{ - void *ptr = MemtxAllocator<ALLOC>::alloc(size + sizeof(uint32_t)); - if (ptr != NULL) { - *(uint32_t *)ptr = size; - return (uint32_t *)ptr + 1; - } - return NULL; -} - -template <class ALLOC> -static void -memtx_free_impl(void *ptr) -{ - ptr = (uint32_t *)ptr - 1; - uint32_t size = *(uint32_t *)ptr; - MemtxAllocator<ALLOC>::free(ptr, size); -} - template <class ALLOC> static inline struct tuple * memtx_tuple_new_raw_impl(struct tuple_format *format, const char *data, @@ -115,8 +90,6 @@ template <class ALLOC> static void memtx_alloc_init(void) { - memtx_alloc = memtx_alloc_impl<ALLOC>; - memtx_free = memtx_free_impl<ALLOC>; memtx_tuple_new_raw = memtx_tuple_new_raw_impl<ALLOC>; } diff --git a/src/box/memtx_engine.h b/src/box/memtx_engine.h index f8735ea42c76cf474335a10af3756dd1700e5448..3d6c039443535fde01906f90ba4ce266b704db58 100644 --- a/src/box/memtx_engine.h +++ b/src/box/memtx_engine.h @@ -231,19 +231,6 @@ enum { MEMTX_SLAB_SIZE = 4 * 1024 * 1024 }; -/** - * Allocates size bytes using the memtx allocator (MemtxAllocator::alloc). - * On error returns NULL. Does not set diag. - */ -extern void * -(*memtx_alloc)(uint32_t size); - -/** - * Frees memory allocated with memtx_alloc. - */ -extern void -(*memtx_free)(void *ptr); - /** * Allocate and return new memtx tuple. Data validation depends * on @a validate value. On error returns NULL and set diag. @@ -252,16 +239,6 @@ extern struct tuple * (*memtx_tuple_new_raw)(struct tuple_format *format, const char *data, const char *end, bool validate); -/** - * Returns the size of an allocation done with memtx_alloc. - * (The size is stored before the data.) - */ -static inline uint32_t -memtx_alloc_size(void *ptr) -{ - return *((uint32_t *)ptr - 1); -} - /** * Allocate a block of size MEMTX_EXTENT_SIZE for memtx index * @ctx must point to memtx engine