3 ms·
And also a well implemented GC (ie probably not python) is more efficient than malloc/free by miles (the way they do it is that they just increment the pointer
by nraynaud 4y ago
And also a well implemented GC (ie probably not python) is more efficient than malloc/free by miles (the way they do it is that they just increment the pointer to the end of the slab without any check ; the MMU will trigger if it's unhappy).
So either you manage your memory by slabs yourself without a GC, but you still don't have access to some code styles (like creating a ton of short lived objects), or you pay your malloc/free dues.
Sometimes, like if you are messing with graphs pointers and malloc (because it's not yet time to refactor to introduce a memory slab system), you can get the worst of both world: you allocate slowly with malloc, but you don't know when to exactly deallocate, so you still have to retain everything until you can nuke the entire graph at once, and each element will require a slow free().