3 ms·
It's not about commanding the GC. It's about avoiding unnecessary allocations.
by enneff 14y ago
It's not about commanding the GC. It's about avoiding unnecessary allocations.
- Locke1689 14y agoOK, can you be specific how this is done? What is the technical reason here?
- enneff 14y agoFor instance, in Go everything is passed by value. If you want to pass a reference, you must pass a reference type (like a pointer). This means that you can pass around structs without having to put them on the heap. In JVM-land, nearly everything is passed by reference, and the data must go on the heap. Relatedly, in Go if you allocate an array of n values of type T, the size of that array in memory is n * sizeof(T), and the items are laid out sequentially in memory. There are no other bookkeeping data structures and no indirection. Here's a story about one project's struggle with data structures and Java: http://marc.info/?l=git&m=124111702609723 http://marc.info/?l=git&m=124111702609723 Relevant quote: JGit struggles with not having an efficient way to represent a SHA-1. C can just say "unsigned char[20]" and have it inline into the container's memory allocation. A byte[20] in Java will cost an *additional* 16 bytes of memory, and be slower to access because the bytes themselves are in a different area of memory from the container object. We try to work around it by converting from a byte[20] to 5 ints, but that costs us machine instructions. In Go, you would just write [20]byte. If you wanted a struct with a field of [20]byte you can do so, and all it costs is the 20 bytes.
- Locke1689 14y agoThe JVM does not support this, but the CLR does.