4 ms·
Sounds like you're conflating GC with Java's limited type/value system. > That's ignoring the fact that a Java object is, at minimum, 11 bytes larger than a C+
by vardump 10y ago
Sounds like you're conflating GC with Java's limited type/value system.
> That's ignoring the fact that a Java object is, at minimum, 11 bytes larger than a C++ object.
In C++ minimum object size is 0 bytes. No virtual methods and no member variables.
> In Java, the same map will give the GC 3 items to keep track of (minimum) per entry in the map, plus half a dozen for the map itself. One for the object that keeps the key and the value, one of the key and one for the value.
This is because of lack of value types in Java, nothing to do with GC. Think of how horrible C/C++ would be if you had only primitive types (char, int, double, etc.), and pointers to objects or primitive arrays.
> That's assuming both key and value are boxed primitives, not actual java objects. In that case, it'll be more.
Boxed primitives are actual Java objects.
> "and C++ smart pointers will wipe the floor with their java tracing equivalent"
No, C++ "smart pointers" (are you talking about std::shared_ptr?) will definitely be slower in amortized runtime costs. High cost of std::shared_ptr is one reason why std::unique_ptr exists.
Disclaimer: C++, not a Java programmer.
- iofj 10y ago> Sounds like you're conflating GC with Java's limited type/value system. Well, yes. It's the JVM that seems to prevent value objects, not Java per se. Since async GC will need RTTI this is going to be more general than just Java (it needs to know, given only memory adress, what the type of the object is, which means it needs at least a pointer in there (these days 8 bytes)). I also don't know any VM that really does a better job. > In C++ minimum object size is 0 bytes. C++ minimum object size is 1 byte (since 2 objects can't have the same address). > Boxed primitives are actual Java objects. I should have been clearer : I meant classes with fields, as apparently a class with a single int is bigger than a boxed Integer in the JVM.