The terms 'pool' and 'buffer' may be used interchangeably here.
Suppose I have a pool I want to allocate at the beginning of the programm, as to not always call new
all the time.
Now, I don't want to artificially limit myself on the size of the pool, but if I reallocate a bigger pool, all pointers to the old one will be invalidated, which certainly isn't very cool.
One way I thought of was "paging", aka
const int NUM_PAGES = 5;
char* pool[NUM_PAGES];
And allocate a new page instead of reallocating only one page. This would let all pointers stay valid, but make the management of the paged-pool a bit more difficult. Also, I'm limiting myself on the number of pages, so in the end again on the size of the pool.
Another way was to have a mapping from the pointers my allocation function returns to pointers to the real memory space. This would let all the old pointers stay valid, but would take more memory and I'd need to write a smart pointer to return from my allocation function which does the mapping.
Which other possible ways to achieve what I want are there? What (dis)advantages have I missed in my above example implementations?
You're talking about something that reminds me of a std::deque
. I'm not really sure if you can use a std::deque
as is, or if you'll simply need to use its basic design to implement some kind of allocator.