1#ifndef BMALLOC__H__INCLUDED__
2#define BMALLOC__H__INCLUDED__
31#if defined(BMSSE2OPT) || defined(BMSSE42OPT)
32#define BM_ALLOC_ALIGN 16
35#define BM_ALLOC_ALIGN 32
37#if defined(BMAVX512OPT)
38#define BM_ALLOC_ALIGN 64
69#if defined(BM_ALLOC_ALIGN)
79 throw std::bad_alloc();
118 void* ptr = ::malloc(n *
sizeof(
void*));
120 throw std::bad_alloc();
166 pool_ptr_[size_++] = ptr;
176 return pool_ptr_[--size_];
179 void allocate_pool(
size_t pool_size)
182 pool_ptr_ = (
void**)::malloc(
sizeof(
void*) * pool_size);
184 throw std::bad_alloc();
199template<
class BA,
class PA>
253template<
class BA,
class PA,
class APool>
265 : block_alloc_(block_alloc),
266 ptr_alloc_(ptr_alloc),
271 : block_alloc_(ma.block_alloc_),
272 ptr_alloc_(ma.ptr_alloc_),
278 block_alloc_ = ma.block_alloc_;
279 ptr_alloc_ = ma.ptr_alloc_;
288 return BA(block_alloc_);
295 return PA(block_alloc_);
301 alloc_pool_p_ = pool;
307 return alloc_pool_p_;
318 if (alloc_pool_p_ && alloc_factor == 1)
319 return alloc_pool_p_->alloc_bit_block();
328 if (alloc_pool_p_ && alloc_factor == 1)
329 alloc_pool_p_->free_bit_block(block);
361 block_alloc_.deallocate((
bm::word_t*)block, len);
369 return ptr_alloc_.allocate(size, 0);
377 ptr_alloc_.deallocate(p, size);
407 ptr = ::malloc(size);
412 throw std::bad_alloc();
414 BM_THROW(BM_ERR_BADALLOC);
430 ::_aligned_free(ptr);
#define BM_DEFAULT_POOL_SIZE
#define IS_VALID_ADDR(addr)
void free_bit_block(bm::word_t *block) BMNOEXCEPT
bm::word_t * alloc_bit_block()
void free_pools() BMNOEXCEPT
pointer_pool_array block_pool_
Default malloc based bitblock allocator class.
static bm::word_t * allocate(size_t n, const void *)
The member function allocates storage for an array of n bm::word_t elements, by calling malloc.
static void deallocate(bm::word_t *p, size_t) BMNOEXCEPT
The member function frees storage for an array of n bm::word_t elements, by calling free.
BM style allocator adapter.
void free_ptr(void *p, size_t size) BMNOEXCEPT
Frees block of pointers.
bm::word_t * alloc_bit_block(unsigned alloc_factor=1)
Allocates and returns bit block.
void * alloc_ptr(size_t size)
Allocates block of pointers.
void set_pool(allocator_pool_type *pool) BMNOEXCEPT
set pointer to external pool
mem_alloc(const BA &block_alloc=BA(), const PA &ptr_alloc=PA()) BMNOEXCEPT
bm::gap_word_t * alloc_gap_block(unsigned level, const bm::gap_word_t *glevel_len)
Allocates GAP block using bit block allocator (BA).
mem_alloc(const mem_alloc &ma) BMNOEXCEPT
block_allocator_type get_block_allocator() const BMNOEXCEPT
Returns copy of the block allocator object.
allocator_pool_type * get_pool() BMNOEXCEPT
get pointer to allocation pool (if set)
void free_bit_block(bm::word_t *block, unsigned alloc_factor=1) BMNOEXCEPT
Frees bit block allocated by alloc_bit_block.
ptr_allocator_type get_ptr_allocator() const BMNOEXCEPT
Returns copy of the ptr allocator object.
mem_alloc & operator=(const mem_alloc &ma) BMNOEXCEPT
void free_gap_block(bm::gap_word_t *block, const bm::gap_word_t *glevel_len)
Frees GAP block using bot block allocator (BA)
APool allocator_pool_type
Pool of pointers to buffer cyclic allocations.
void * pop() BMNOEXCEPT
Get a pointer if there are any vacant.
pointer_pool_array(const pointer_pool_array &)=delete
pointer_pool_array & operator=(const pointer_pool_array &)=delete
unsigned push(void *ptr) BMNOEXCEPT
Push pointer to the pool (if it is not full)
Default malloc based bitblock allocator class.
static void * allocate(size_t n, const void *)
The member function allocates storage for an array of n void* elements, by calling malloc.
static void deallocate(void *p, size_t) BMNOEXCEPT
The member function frees storage for an array of n bm::word_t elements, by calling free.
bm::alloc_pool< block_allocator, ptr_allocator > standard_alloc_pool
bm::mem_alloc< block_allocator, ptr_allocator, standard_alloc_pool > standard_allocator
unsigned gap_capacity(const T *BMRESTRICT buf, const T *BMRESTRICT glevel_len) BMNOEXCEPT
Returs GAP block capacity.
void aligned_free(void *ptr) BMNOEXCEPT
Aligned free.
void * aligned_new_malloc(size_t size)
Aligned malloc (unlike classic malloc it throws bad_alloc exception)
const unsigned gap_levels
const unsigned set_block_size
unsigned short gap_word_t