News for hackers. Stuff that matters.
Re:C/C++ vs. Rust Performance by vvanders on Sunday November 01, 2020 @01:16PM (#24961312)
Even then last I looked C++ doesn't have it either, it's exclusively a C99 feature.

For me the downsides outweigh the upsides of alloca and I usually find other approaches(free list, arenas, etc).

Re:C/C++ vs. Rust Performance by Someone on Sunday November 01, 2020 @01:30PM (#24961402)
When comparing rust and C++, I think it’s unfair to interpret “C++” as a specific standard, because you can’t do the same with rust. So, you would have to compare implementations.

AFAIK, in practice, many C++ compilers support alloca for compatibility with gcc (or more specifically, its C library)

Also, is alloca part of any C standard? I can’t find evidence for that easily. Also, if so, https://en.wikipedia.org/wiki/Stack-based_memory_allocation#... needs updating. It currently says

“The function was present on Unix systems as early as 32/V (1978), but is not part of Standard C or any POSIX standard.”

I also don’t see how it could be part of the standard, as that, AFAIK, doesn’t even specify the existence of a call stack (a compiler is free to allocate call frames on the heap, for example)

Re:C/C++ vs. Rust Performance by vvanders on Sunday November 01, 2020 @01:49PM (#24961518)
Most C++ compilers I've worked wouldn't let you use it unless the compilation unit was compiled as C and then linked externally.

In the same way I could totally define alloca in a C symbol and then just extern it into Rust if I wanted to.

[edit]

Realized I was thinking of VLAs but I think the point still stands.

Re:C/C++ vs. Rust Performance by Someone on Sunday November 01, 2020 @02:11PM (#24961700)
Reading https://www.gnu.org/software/gnulib/manual/html_node/alloca...., I think gcc C++ supports alloca on most systems (“There are a few systems where this is not possible: HP-UX systems, and some other platforms when the C++ compiler is used. On these platforms the alloca module provides a malloc based emulation”)

VLAs are different, I think.

Re:C/C++ vs. Rust Performance by gpderetta on Sunday November 01, 2020 @02:07PM (#24961656)
C has standardized dynamically sized automatic arrays which is close enough to alloca. The standard wouldn't concern itself of were the space is actually allocated, just mandate that it is freed when the function terminates.
Re:C/C++ vs. Rust Performance by ncmncm on Sunday November 01, 2020 @10:40PM (#24964635)
Removed from the last C Standard. It was recognized as a mistake.
Re:C/C++ vs. Rust Performance by gpderetta on Monday November 02, 2020 @05:22AM (#24966460)
Not so much removed but made optional (see __STDC_NO_VLA__), but I guess it is close enough.
Re:C/C++ vs. Rust Performance by kllrnohj on Sunday November 01, 2020 @01:38PM (#24961447)
I've found just applying SSO to the container sufficient. Stack if it's small enough, heap if it isn't. You usually want a limit on your alloca anyway.