Stack vs Heap Allocation Tradeoffs

Erik Engheim
1 min readFeb 10, 2017

One issue I was searching through the article to find was a discussion of the impact of Go’s GC strategy in relation to design of the language itself. Almost every object in Java is heap allocated as Java doesn’t support custom value types, and pointers.

As someone who has spent the biggest part of his life with C/C++ manually memory management and Objective-C/Swift style systems it appeals to me greatly that Go gives you similar control over memory layout as C. Since you can nest structs and keep arrays of structs in contiguous memory it seems obvious to me that there are much more opportunities to reduce the number of heap allocations in Go compared to Java. I had hoped to see a discussion of the implications of this. I would speculate that will reduce the strain on the Go GC compared to the one in Java.

As an old C guy I love that it is fairly easy to create your own secondary memory allocators. I am no Java expert but it would strike me as more difficult and less of an advantage to do that in Java.

--

--

Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.