"A blog post by Noel Llopis I think will give some insight to people wondering about how some games manage the block of memory internally once they have it:
gamesfromwithin.com/start-pre-allocating-and-stop-worrying"
This is an decent article, yet it is incomplete, imo.
There are problems with both methods that are left out. The biggest problem with the "preallocation" form, is that you can exhaust the adresspace, even when there is memory available. On x64 this isn't a problem. But on other plattforms, it is a real problem that must be solved, unless you know exactly what your bounds are.
If you know your bounds, exactly. Then the way Casey does it, is the very best.
But chances are that you don't.
Another thing the article leaves out, is paging. Paging is WAY more costly then the allocator itself. And so it should have been mentioned. Paging will hurt you no matter which way you design your memory allocations. And it is (can be) about as costly as a copy.
The problems with a generic memory allocator is mentioned in the article. Except for bugs. Small bugs, that will happen, in code that is complex, can pervert the memorymanager. And when this happens, all bet's are off. And it will happen.
Preallocation will not allow for unknown quantities of objects of an unknown size. If it is possible that the worst case can happen, then it will happen, hehe, and you end up dumping virtual memory space on covering up for the worst case. While hurting the common case.
I think the best is to combine the two strategies. Create an memory allocator, which is fully dynamic, and then, preallocate objects in it. The allocator should have properties that allows you to avoid all searching.
The allocator should have the debugger built into its structures. It will require a considerable amount of overhead. But this overhead can, in all cases, be devided by preallocating objects. And it has the advantage of speed.
If you preallocate 1000 objects, then you can cut overhead and speed of allocations in 1000. I am not saying you SHOULD always do this. But when you need to. This last point is important. There is no way to ensure performance if you do not want to get into the spesifics.
Before you write an allocator, I would advice you should THOUROUGHLY test VirtualAlloc or whatever you use for systemallocation. This mean you need to do a lot more than just make one or even a 1000 alloations with it, and call it the day. You need to stress-test it. You need to uncover it's weakness. So that you can design around it. This is almost impossible to do for the long term. Since they can change it at any time. Which is why no performant origented person wants to call to a library in the first place. But today, we don't really have a choice.
I wouldn't assume what anyone says about it, to be true. I have really not found a single person who truely knows. A problem is that since it can change at any time, anything you say about it can be wrong tomorrow. So I will not do that. You need to find out yourself.
If you write your allocator as an object, you can create more then one, that can be called in a similar way. That way, when you run into problems in a large codebase, or in multithreaded code, you can put suspicious objects into their own allocator. This also avoid the need to lock those allocations. This create even more overhead, but it will be worth it.
NB! Memory allocated by an allocator, is just as much GLOBAL memory, as memory allocated as global static memory.