On Wednesday, 10 April 2013 at 09:06:40 UTC, Manu wrote:
Actally, now that I think about it though, I do something like
this a lot
in games.
I have a block of memory that only lasts the life of a single
frame, any
transient allocations go in there, and they are never released,
the pointer
is just reset and it overwrites the buffer each frame.
Allocation is virtually instant: void* alloc(size_t bytes) {
offset +=
bytes; return buffer[offset-bytes..offset]; }
and releasing: offset = 0;
This is a great realtime allocator! ;)
I usually have separate allocation functions to do this, but in
D there is
the problem that all the implicit allocations (array
concatenation/strings/etc) can't have their alloc source
controlled :/
Well, avoid all implicit allocations and you can do something
like that already right now. My initial comment was inspired by
recent uprising of "scope" discussion - it fits the concept
allowing such implementation to be not only fast but also
type-safe.