Skip to content

Common Interface of all Allocators

Felix Petriconi edited this page Feb 11, 2014 · 2 revisions

Block allocate(size_t n)

Allocates n or more bytes. If the Allocator is out of memory it returns an empty Block.

bool reallocate(Block& b, size_t n)

Reallocates for the given Block b n bytes. If the reallocation was successful, then true is returned, other wise false. The pointer of b.ptr might change, but the content of min(b.length, n) bytes is preserved.

void deallocate(Block& b)

Deallocates the provided Block b and resets it.

bool expand(Block& b, size_t delta)

Expands the given Block b by delta bytes. If enough contiguous memory is available, then true is returned, otherwise false. It is guaranteed that the b.ptr stays the same. (Not all Allocator implement this.)

bool owns(const Block& b) const

Returns true, if the Allocator owns this Block, otherwise false. (Not all Allocator implements this.)

void deallocateAll()

Frees all memory that was provided by this Allocator. (Not all Allocator implements this.) Saved client Blocks become to dangling pointers!