VLA's in general were considered to be a bad idea in C99, and the itty-bitty-shitty-commitee for c++ only seems to care about non core language things, templates, stl crap; they would never put in something as type-unsafe as VLAs.
I took about 20 minutes today to try and improve upon VLAs and alloca(), and came up with this:
Code:
void Proc() {
LOCAL_STACK(4000); // No way to emit this without compiler support.
Foo* foo = stackalloc Foo();
Bar* bar = stackalloc Bar[64];
u8* buffer = (u8*)stackalloca(MEGABYTES(8)); // Perfectly safe! Fall back to backing allocator.
//cleanup if any
}
The coolest thing is actually stuff like this though;
Code:
StackArray<char*> ScanDirectory(const char* path)
{
StackArray<char*> filenames;
//get all the files in the directory without allocating memory
return filenames; //no local sp, does not reset from scope. // no deep copy
}
Which (to me at least) is better and safer than VLAs and alloca(). Of course I'd have to benchmark this in actual code, but I suspect it's only 4 asm instructions overhead over the fixed "char buf[2048]" approach.