News for hackers. Stuff that matters.
Re:Legitimate Use of Variable Length Arrays by chrisseaton on Monday October 28, 2019 @08:53AM (#21376423)
> Stack allocations are trivial and fast by comparison: Allocation is a matter of bumping the stack pointer, and no synchronization is needed.

And this is why runtimes with moving garbage collectors can be faster than malloc - allocation with such a GC is always this cheap even when it's to the heap. (The costs move elsewhere, of course, but ideally to another thread, and are temporally and spatially grouped so that the work uses cache better.)

Re:Legitimate Use of Variable Length Arrays by flohofwoe on Monday October 28, 2019 @09:16AM (#21376632)
Allocation is always cheap, also with manual memory management. It's reclaiming/freeing memory which is the tricky part ;)

Best approach is still to minimize dynamic allocation as much as possible. One can often get surprisingly far with an entirely static memory layout that's defined upfront at application start.

Re:Legitimate Use of Variable Length Arrays by scott_s on Monday October 28, 2019 @10:40AM (#21377398)
In support of flohofwoe's point: good implementations of malloc will, on the common path, just bump a pointer without synchronization. The allocation path of good manual allocator implementations and garbage collectors will probably look similar.
Re:Legitimate Use of Variable Length Arrays by chrisseaton on Monday October 28, 2019 @03:24PM (#21380568)
> In support of flohofwoe's point: good implementations of malloc will, on the common path, just bump a pointer without synchronization.

How does this work when the heap address space becomes fragmented, with randomly distributed available space and objects that are still live? You can't just bump when the next piece of memory may still be in use, and when you're not able to move memory.

Re:Legitimate Use of Variable Length Arrays by lonelappde on Monday October 28, 2019 @05:04PM (#21381648)
That's the uncommon path.
Re:Legitimate Use of Variable Length Arrays by scott_s on Tuesday October 29, 2019 @09:57AM (#21387191)
Yes, exactly. And! It exists in garbage collectors, too.
Re:Legitimate Use of Variable Length Arrays by chrisseaton on Tuesday October 29, 2019 @11:54AM (#21388565)
Why would you ever encounter a fragmented Eden in a garbage collector?
Re:Legitimate Use of Variable Length Arrays by scott_s on Tuesday October 29, 2019 @05:56PM (#21392523)
I wasn't thinking of that case in particular, but that there are other instance in a garbage collector where you will not just be able to bump a pointer: you need to request more memory from the OS, or you need to start a collection phase before satisfying a memory request.
Re:Legitimate Use of Variable Length Arrays by bdisnainc on Monday October 28, 2019 @12:19PM (#21378305)
Very good GCs can be faster compared to common system allocators while minimizing the STW moment, but you cannot beat using a proper allocator for your needs.
Re:Legitimate Use of Variable Length Arrays by chrisseaton on Monday October 28, 2019 @10:31PM (#21383812)
> but you cannot beat using a proper allocator for your needs

How do you know this to be true?

And why isn't a GC a 'proper' allocator?