I was given the assignment of making my own memory manager class, but I really have no idea where to start. My instructions are;
//1> write a memman allocation function
//2> insure the alloce functions returns unused addresses
//3> once all memman memmory is used up, subsequent alloces return NULL
//4> enable freeing of memory and subsequent reuse of those free'd regions
I’ve tried searching around for any guides on dealing with memory allocation, but I have not been too successful.
Here is one very, very naive idea to get you started:
All the memory is statically allocated, so you don’t need any library calls to get your initial chunk of memory. We make sure to return only pointers with maximal alignment (hardcoded to 16 here, though this should be a constant like
sizeof(std::maxalign_t)). This version doesn’t allow for any reclamation, and it’s missing the overflow checks.For reclamation, you could try and write a free list.
As a slight variation, you could make your array be an array of
maxalign_ts, which would simplify the stepping logic a bit. Or you could make it an array ofuintptr_tand use the memory itself as the free list.