you have a scratch buffer objects a placement-new'd into for ease of construction but never deleted from, the allocation pointer is just reset to the start each frame; useful for things like rendering when you need to build temp data structures).
that's how my render queue works! <g>
the queue buffer and index buffers are allocated at load time (in the data segment - of course <g> ).
to clear the queue, you just set the queue pointer and number of index entries to zero
This has nothing to do with 'asset size > ram'; this is all about keeping things clean. If I don't need that memory allocated then why hang on to it?
ok, this makes sense, i do the same sort of thing. i'll unload startup screens before loading game assests - don't need them anymore - a waste of GPU ram. and i'll allocate large temp buffers on the heap for file i/o - the heap is the only logical place to do it.
but for non-temporary data, i use the data segment, or an array in the data segment with pointers to the heap, where the heap ram is sequentially allocated and deallocated just once (asset load for a chunk / level / game). for big temporary data, i use the heap, and for small temporary data i use the stack.
i use static array implementations of doubly linked lists for pretty much everything. they tend to be simpler and faster than traditional doubly linked lists implemented on the heap. the downside is you must set the max size at compile time, instead of the limit being up to the liimits of available ram.
but as i said before, i'm not doing monster engines. i'm mostly doing basic sims with 100 targets max kinda thing. so setting sizes upfront isn't too difficult. start with MAXTGTS=100. maybe kick it to 200 before release, that kind of thing.
a very specific example where you apparently don't care about wastage or good software design (hint: global things are bad software design but having seen your code in the past this doesn't surprise me in the least...)
ah, too true! 99% of the time, the entire projectiles array is empty. heck, most of the time, the entities list is empty too! its just the player list that has anything in it. and its usually 90% empty.
as for global, yes its bad. its unsafe - easy to misuse. the safety lacking in the code syntax must be replaced with coding policies and methodologies which must be well documented, and rigorously followed with strict coder discipline to avoid problems. but its the way i started, so i'm used to it. in the long run, all i really use it for its to avoid calling setter and getter methods everywhere. i suspect that it might be possible to write a game where all data is in private modules acessable only via getter and setter methods, and then you have control code modules that call getter and setter methods and perform operations on the values. the only thing that any data module would have to know about any other module would be any custom data structure definitions used to get and set its values. the only thing controller code modules would need to know would be custom data structures used to get and set values of data modules they use. an extremely modular system. but as you can see, there would be a lot of get and set calls. granted , many might get inlined, but i just bypass them and do the assignments directly, IE:
tgt.active=1;
vs
void activate_tgt(int i)
{
tgt.active=1;
}
or
strucs tgtrec {
...
void activate()
{
active=1;
}
}; // end struct
tgt.activate();
Fixed compile time buffers are the devil; the flexibility gained from just pulling from the heap for a value pulled from a config file far outweighs anything else in the general case.
so for the general case you advocate going data driven for the sizes of such data structures, and using the heap. yes this makes perfect sense. its simply matter of scale. my current projects are small enough i can get away without it. think about it, if you were going to code breakout or galaga, or space invaders or missile command or pong right quick and dirty, you wouldn't break out unity, and start creating CES systems and whatnot - its overkill: "using a tank to squash an ant" as they used to say in design sciences. you'd load up a couple bitmaps, and declare a few variables, and go for it. especially if you'd done it dozens of times before. for me, writing these sims (other than caveman - its a whole different sort of beast) is kind of like that.