Memory Allocation
Enigma via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 29 12:19:48 PDT 2017
I have a memory buffer allocated using different methods. It is
simply a pointer and a size.
I would like to be able to manage this buffer by treating it as a
memory pool or heap. I think I can use allocators to do this but
not sure how.
Effectively I want something like new or malloc but it pulls from
the memory buffer rather than the program heap.
// Allocated once at program start
void* FancyBuffer = FancyAlloc(1000);
Then when I want to use the buffer I'll do stuff like
auto myptr = FancyMalloc(10);
....
FancyFree(myptr);
or whatever.
The main thing is, I don't want to have to write my own allocator
to manage this buffer as it seems that D's allocators would do a
better job.
I imagine that most of the time the buffer will not have more
than one piece of code using it(no overlapping uses) but since I
won't be 100% sure, I need allow for the cases where there might
be overlapping usage. (else I wouldn't ever have to worry about
"allocating or releasing" from it.
Thanks.
More information about the Digitalmars-d-learn
mailing list