|
|
|
|
|
by kaba0
1637 days ago
|
|
Your comparison would only be fair if the alternative (malloc/object pool) would not have more memory than strictly necessary either. But malloc and friends usually do what a very basic GC would (make separate pools for differently sized “objects”). While object pools also need much more memory unless it is full. So all in all, GCs do trade off more memory for more efficient allocation/deallocation but that is a conscious (and sane) tradeoff to make for like 99% of applications as memory stored on RAM doesn’t consume much energy compared to doing GC cycles like a mad man. Also, it is quite configurable in case of JVM GCs. |
|
As for the energy efficiency, I seriously doubt that bringing all memory into cache once in a while, including memory that is not needed frequently by the application, only in order to find live vs dead memory is all that energy efficient. The allocation itself is indeed typically slightly faster but the marking and compaction is additional cost you don't have to pay in manual memory management.