3 ms·
Only theoretically. It is not possible to implement a GC as efficient as Java GCs for C++. Pointer arithmetic, placement new, and other low level features make
by pkolaczk 8y ago
Only theoretically. It is not possible to implement a GC as efficient as Java GCs for C++. Pointer arithmetic, placement new, and other low level features make it hard to determine pointers from non-pointers and to move things in memory.
- kazinator 8y ago"It is not possible" claims are very hard to substantiate. Java is just someone's C++ program. > "Pointer arithmetic, placement new, and other low level features make it hard to determine pointers from non-pointers and to move things in memory." Real applications in a garbage collected language are mixtures of the managed code, plus unmanaged components (like foreign libraries). Garbage collected C++ can work in much the same way: there is a framework for managed code that uses GC, and then there are unsafe parts that are analogous to foreign code. (Except, the managed code can much more easily and efficiently interact with this code than the typical FFI.) There is more than one way to integrate garbage collection into C++, in any case.
- kazinator 8y ago> move things in memory. Not all garbage-collection schemes move things in memory; only copying and/or compacting garbage collectors do.