News for hackers. Stuff that matters.
Re:Go does not need a Java-style GC by jeeeb on Tuesday November 23, 2021 @03:54PM (#29323376)
FWIW. This would probably present a challenge in most (all?) languages.

For example in libc++ due to SSO an std::string has a minimum size of 24 bytes.

For a billion strings less than 15 chars (+ the null byte) that gets you to 24GB, and that’s optimistically assuming each string is allocated in place.

I doubt heap allocated char* would do much better either. Just having a billion 8 byte pointers eats a lot of memory. You’d really need some sort of string packing scheme similar to what you did in Java.

Re:Go does not need a Java-style GC by marginalia_nu on Tuesday November 23, 2021 @04:25PM (#29323758)
It's a lot easier to build custom allocators in C++ though.

For one, Java has a maximum mmap-size of 2 Gb, and as a cherry on top of that turd, you have no control over their lifecycle. The language is very clearly not designed for this type of work, and if you try to make it do it anyway, it fights you every step of the way.

Re:Go does not need a Java-style GC by _old_dude_ on Tuesday November 23, 2021 @06:03PM (#29324668)
It has nothing to do with the language but with the API / VM capabilities.

Both those restrictions are fixed, granted that this is not yet in the offical API, it's an incubation module (the equivalent of from __future__ of Python).

https://docs.oracle.com/en/java/javase/17/docs/api/jdk.incub...

Re:Go does not need a Java-style GC by kasperni on Tuesday November 23, 2021 @06:00PM (#29324646)
The foreign memory API which is currently incubating should help with most of these limitations: https://openjdk.java.net/jeps/419
Re:Go does not need a Java-style GC by native_samples on Wednesday November 24, 2021 @06:30AM (#29328938)
Right - specifically they invented a way to make closing an mmapped segment safe and fast. The reason you can't officially (without private APIs) unmap something in current Java is because if you did then other threads would segfault, and "no segfaults" is kind a defining characteristic of Java. The new API fixes this using more VM magic, so closing a mapping from one thread will cause other threads to throw exceptions, but this is done without sacrificing performance (it doesn't require checking a status every time you read from memory).