News for hackers. Stuff that matters.
Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free by int_19h on Monday October 29, 2018 @01:46PM (#18329458)
The problem with vector is that it always heap-allocates. The ideal approach is the one where small allocations are on the stack, and large ones are on the heap, without the API user having to do anything about it.

C++ has had a proposal for std::dynarray floated for a while, which would basically have semantics allowing stack allocation, but wouldn't mandate it, leaving it as a quality of implementation issue (so it would be legal to implement it on top of vector, but it was assumed that compilers would go for optimizations given the opportunity). It didn't pass, unfortunately.

Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free by maxlybbert on Tuesday October 30, 2018 @08:16AM (#18335776)
I guess in theory, you could pull it off with a very clever allocator. Bloomberg’s BDE has an allocator along those lines ( https://bloomberg.github.io/bde/classbdlma_1_1BufferedSequen... ), but I don’t think it made it into the standard (memory_resource header).

My point is only that runtime-sized arrays may have made it into the C standard, but they aren’t in the C++ standard.

Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free by geezerjay on Tuesday October 30, 2018 @04:40AM (#18334782)
> The problem with vector is that it always heap-allocates.

How about std::array ?

Re:The Linux Kernel Is Now VLA (Variable-Length Array) Free by int_19h on Tuesday October 30, 2018 @04:44AM (#18334809)
It's not dynamically sized - the size is a template parameter, which means that it has to be a compile-time constant.