I'm making an allocator with different allocation strategies. One of these strategies is a stack allocation.
I want to preallocate a large block of memory and pick from this space when allocating memory. The picking would be sequential so it would resemble to a stack.
In theory it seems fine. But how can I return chunks of such a memory block?
Suppose a quick draft (see comment in allocate):
So, any idea how I could return the address in myMemory that happens to be at the given index?Code:
myMemory = ::operator new(LOTS);
void* allocate(int size)
// what i'm trying is this
// problem is, compiler doesn't know the size of void*
// i'm sure there's a way to do this, but i don't know any
void* result = myMemory + index;
index += size;
Any way to do this without templating (allocator relies on an abstract strategy that can be stack, heap, etc)?