Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it worth caching objects created by Delphi's Memory Manager?

I have an application that creates, and destroys thousands of objects. Is it worth caching and reusing objects, or is Delphi's memory manager fast enough that creating and destroying objects multiple times is not that great an overhead (as opposed to keeping track of a cache) When I say worth it, of course I'm looking for a performance boost.

like image 332
Steve Avatar asked Nov 02 '08 21:11

Steve


2 Answers

From recent testing - if object creation is not expensive (i.e. doesn't depend on external resources - accessing files, registry, database ...) then you'll have a hard time beating Delphi's memory manager. It is that fast.

That of course holds if you're using a recent Delphi - if not, get FastMM4 from SourceForge and use it instead of Delphi's internal MM.

like image 181
gabr Avatar answered Oct 20 '22 17:10

gabr


Memory allocation is only a small part of why you would want to cache. You need to know the full cost of constructing a semantically valid object, and compare it with the cost of retrieving items from the cache, and not just for a micro-benchmark: cache effects (CPU cache, that is) may change the runtime dynamics in a real live running application.

Or to put it another way, measure it and find out. If you're not measuring, you're not engineering, just guessing.

like image 38
Barry Kelly Avatar answered Oct 20 '22 19:10

Barry Kelly