boost::mixin::global_allocator
// In header: <boost/mixin/allocators.hpp> class global_allocator { public: // construct/copy/destruct global_allocator(); ~global_allocator(); // public member functions char * alloc_mixin_data(size_t); void dealloc_mixin_data(char *); void alloc_mixin(size_t, size_t, char *&, size_t &); void dealloc_mixin(char *); bool has_allocated() const; // public static functions static size_t calculate_mem_size_for_mixin(size_t, size_t); static size_t calculate_mixin_offset(const char *, size_t); // public data members static const size_t mixin_data_size; };
The class should be the parent to your custom allocators, i.e. allocators that are set for all mixin allocation
global_allocator
public member functionschar * alloc_mixin_data(size_t count);
Pure virtual. Should return a valid pointer to an array with the size of count
mixin_data_in_object
instances.
Use the static constant mixin_data_size
to get the size of a single mixin_data_in_object
Example:
char* my_allocator::alloc_mixin_data(size_t count) { return new char[count * mixin_data_size]; }
void dealloc_mixin_data(char * ptr);
Pure virtual. Should free the memory that has been obtained via a call to alloc_mixin_data
.
void alloc_mixin(size_t mixin_size, size_t mixin_alignment, char *& out_buffer, size_t & out_mixin_offset);
Pure virtual. Should return memory for a mixin instance. The library will request a buffer in which to put the mixin. Overrides of this method should fill the output parameters with the address of the allocated memory and the offset of the mixin (according to the alignment) BUT IN SUCH A WAY AS TO ALLOW A POINTER TO BE PLACED IN FRONT
You may use calculate_mem_size_for_mixin
and calculate_mixin_offset
if you're not sure what to do.
Example:
void your_allocator::alloc_mixin(size_t mixin_size, size_t mixin_alignment, char*& out_buffer, size_t& out_mixin_offset) { size_t mem_size = calculate_mem_size_for_mixin(mixin_size, mixin_alignment); out_buffer = new char[mem_size]; out_mixin_offset = calculate_mixin_offset(out_buffer, mixin_alignment); }
void dealloc_mixin(char * ptr);
Pure virtual. Should free the memory that has been obtained via a call to alloc_mixin
.
bool has_allocated() const;
global_allocator
public static functionsstatic size_t calculate_mem_size_for_mixin(size_t mixin_size, size_t mixin_alignment);
Calculates appropriate size for a mixin buffer so as to satisfy the requirements of mixin size and alignment AND leave a room for its owning object in front.
You may use it in your overrides of alloc_mixin
to determine the appropriate memory size.
static size_t calculate_mixin_offset(const char * buffer, size_t mixin_alignment);
Calculates the appropriate offset of the mixin in the buffer so as to satisfy the requirements of its alignment AND leave a room for its owning object in front.
You may use it in your overrides of alloc_mixin
to determine the correct mixin_offset.