4 ms·
I hope you realize that stack allocation can replace a lot of allocation that would be done by a GC? And that having control over memory layout can lend itself
by physguy1123 11y ago
I hope you realize that stack allocation can replace a lot of allocation that would be done by a GC? And that having control over memory layout can lend itself to better performance? And that naively mallocing everywhere is not the only or fastest way to manually manage memory, and sometimes isn't even the easiest.
- giovannibajo1 11y agoGo also has stack allocations for objects based on escape analysis; basically, if the compiler can prove that a variable doesn't escape, it is allocated on the heap, otherwise on the heap. Improvement on escape analysis in the compiler thus reduce also the heap size by allocating more things onto the stack.
- tokenrove 11y agoMany GC'd languages also have stack allocation (see dynamic-extent in Common Lisp, for example); when talking about GC vs malloc (already an over-simplified dichotomy), we should be talking about heap allocations of indefinite extent.
- pjmlp 11y agoMany GC languages have stack and global static memory allocation as well. Go being one of them. Others, Oberon family of languages, Modula-3, D, Eiffel and even .NET to a certain extent. Having managed heap doesn't mean other allocation types aren't available.