Go to the documentation of this file. 1 #ifndef BMALLOC__H__INCLUDED__
2 #define BMALLOC__H__INCLUDED__
31 #if defined(BMSSE2OPT) || defined(BMSSE42OPT)
32 #define BM_ALLOC_ALIGN 16
34 #if defined(BMAVX2OPT)
35 #define BM_ALLOC_ALIGN 32
37 #if defined(BMAVX512OPT)
38 #define BM_ALLOC_ALIGN 64
69 #if defined(BM_ALLOC_ALIGN)
81 throw std::bad_alloc();
121 void* ptr = ::malloc(n *
sizeof(
void*));
124 throw std::bad_alloc();
171 pool_ptr_[size_++] = ptr;
181 return pool_ptr_[--size_];
184 void allocate_pool(
size_t pool_size)
186 pool_ptr_ = (
void**)::malloc(
sizeof(
void*) * pool_size);
188 throw std::bad_alloc();
203 template<
class BA,
class PA>
259 template<
class BA,
class PA,
class APool>
270 mem_alloc(
const BA& block_alloc = BA(),
const PA& ptr_alloc = PA())
271 : block_alloc_(block_alloc),
272 ptr_alloc_(ptr_alloc),
277 : block_alloc_(ma.block_alloc_),
278 ptr_alloc_(ma.ptr_alloc_),
284 block_alloc_ = ma.block_alloc_;
285 ptr_alloc_ = ma.ptr_alloc_;
294 return BA(block_alloc_);
301 return PA(block_alloc_);
307 alloc_pool_p_ = pool;
313 return alloc_pool_p_;
324 if (alloc_pool_p_ && alloc_factor == 1)
325 return alloc_pool_p_->alloc_bit_block();
334 if (alloc_pool_p_ && alloc_factor == 1)
335 alloc_pool_p_->free_bit_block(block);
367 block_alloc_.deallocate((
bm::word_t*)block, len);
374 return ptr_alloc_.allocate(size, 0);
382 ptr_alloc_.deallocate(p, size);
405 #ifdef BM_ALLOC_ALIGN
412 ptr = ::malloc(size);
417 throw std::bad_alloc();
419 BM_THROW(BM_ERR_BADALLOC);
433 #ifdef BM_ALLOC_ALIGN
435 ::_aligned_free(ptr);
446 #undef BM_ALLOC_ALIGN
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.
APool allocator_pool_type
void free_bit_block(bm::word_t *block)
Pool of pointers to buffer cyclic allocations.
pointer_pool_array & operator=(const pointer_pool_array &)=delete
static void deallocate(bm::word_t *p, size_t)
The member function frees storage for an array of n bm::word_t elements, by calling free.
void set_pool(allocator_pool_type *pool)
set pointer to external pool
static void * allocate(size_t n, const void *)
The member function allocates storage for an array of n void* elements, by calling malloc.
const unsigned set_block_size
void * pop()
Get a pointer if there are any vacant.
bm::alloc_pool< block_allocator, ptr_allocator > standard_alloc_pool
void * aligned_new_malloc(size_t size)
Aligned malloc (unlike classic malloc it throws bad_alloc exception)
ptr_allocator_type get_ptr_allocator() const
Returns copy of the ptr allocator object.
void free_gap_block(bm::gap_word_t *block, const bm::gap_word_t *glevel_len)
Frees GAP block using bot block allocator (BA)
void free_bit_block(bm::word_t *block, unsigned alloc_factor=1)
Frees bit block allocated by alloc_bit_block.
bm::word_t * alloc_bit_block()
Default malloc based bitblock allocator class.
mem_alloc(const BA &block_alloc=BA(), const PA &ptr_alloc=PA())
unsigned short gap_word_t
#define BM_DEFAULT_POOL_SIZE
mem_alloc & operator=(const mem_alloc &ma)
void aligned_free(void *ptr)
Aligned free.
unsigned push(void *ptr)
Push pointer to the pool (if it is not full)
bm::word_t * alloc_bit_block(unsigned alloc_factor=1)
Allocates and returns bit block.
void free_ptr(void *p, size_t size)
Frees block of pointers.
#define IS_VALID_ADDR(addr)
bm::mem_alloc< block_allocator, ptr_allocator, standard_alloc_pool > standard_allocator
pointer_pool_array block_pool_
allocator_pool_type * get_pool()
get pointer to allocation pool (if set)
void * alloc_ptr(size_t size)
Allocates block of pointers.
bm::gap_word_t * alloc_gap_block(unsigned level, const bm::gap_word_t *glevel_len)
Allocates GAP block using bit block allocator (BA).
static void deallocate(void *p, size_t)
The member function frees storage for an array of n bm::word_t elements, by calling free.
block_allocator_type get_block_allocator() const
Returns copy of the block allocator object.
mem_alloc(const mem_alloc &ma)
unsigned gap_capacity(const T *buf, const T *glevel_len)
Returs GAP block capacity.
Default malloc based bitblock allocator class.
const unsigned gap_levels
BM style allocator adapter.