I'm porting some C code for arena allocator to D, and somehow the flexible array members (a feature of C99 for dynamically-sized structs) work in D without significant changes in the code. Here's my arena definition:
struct ArenaChunk {
size_t size;
ArenaChunk* next;
char[] memory; // flexible array member
}
struct Arena {
ArenaChunk* firstChunk;
ArenaChunk* currChunk;
int currInd;
}
And here's how I use the FAM's memory for allocating stuff:
void* result = cast(void*)(&ar.currChunk.memory + ar.currInd);
This seems to work, but I'm a little doubtful, does D really support FAMs in the same way as C, or am I misusing some other D feature here? I mean, FAM's aren't even supported by C++, and aren't listed on the D reference yet somehow the code works.