From: Shigeru C. <ch...@is...> - 2003-02-18 14:17:01
|
From: Grzegorz Jakacki <ja...@he...> Date: Tue, 18 Feb 2003 14:30:58 +0800 (CST) > > > > Memory management with smart pointers > > > > should be slower than with GC... > > > > > > Why? I do not disagree, but I am still looking for convincing argument. > > > > Yes, the performance depends on memory usage patterns. > > > > GC should work better if a large number of objects are allocated and > > soon deallocated before the next GC phase. Suppose that 100 objects > > are allocated and then 90 of them are deallocated. The deallocation > > cost with smart pointers is 90 * <time for free()>. On the other hand, > > if GC (except reference counting GC) is used, the deallocation cost > > is 10 * <time for collecting a live object>. > > Doesn't GC has to free those 90 dead (leaked) objects anyway? Oops, the example above is for a copying GC (or any other modern GC) but conservative GC is mark-sweep GC (as far as I know). If GC is a copying GC (or any other modern GC), the whole memory region including the dead objects is deallocated after live objects are taken from that region to another region. So the deallocation cost is in principle independent of the number of dead objects. It depends on the number of live objects. But I still think conservative GC (mark-sweep GC) is mostly better than smart pointers, which is based on reference counting GC. For example, creating and deleting smart pointers includes runtime penalties due to maintaining reference counts. If mark-sweep GC is used, such a house-keeping job is done only at GC time. Forthermore, smart pointers introduce extra indirection to every access. Chiba |