Object Creation (was objpool) again
- From: "Gabriel Corneanu" gabrielcorneanuATyahoo.com
- Date: 6 Oct 2005 02:15:55 -0700
Hi all,
As Eric said, when the memory manager if good enough there might not be a further speed increase using pooling. One or to extra calls (to the MM) might be balanced by the extra FreeInstance redirection.
In my tests this approach is pretty fast and somehow easier to follow than the other version, so I focused mainly on this variant.
Eric already added different handling for different types for classes (see below).
My changes (from Eric's version):
- renamed unit to FastObj and the main class to TObjectAccelerator
there is no explicit pooling anymore in this version
- created allocator for dynamic code
- created option to disable global optimization
use OptimizeClass instead to optimize individual classes
- switch for version independent (no direct calls to FastMM)
- fixed memory leaks
- removed class name from offset asm statements, to avoid trouble when
renaming the class (already did)
Some people with better ASM knowledge could help optimizing the loops.
As I can see now, it should work as long as these conditions are met:
For interfaced objects, a full copy is made from the template. This means it will work if all values set in AfterConstruction are static (nothing like Random() :) ); that's the way TInterfacedObject works.
For non interfaced objects, the content is zeroed. It will NOT work if any value is set in AfterConstruction.
I have never seen classes which would fail on these conditions.
Some questions for Eric (and anyone else interested):
You used several Int64 conversions in pointer operations. I think you did this to prepare for 64 bit version.
In my opinion this is not necessary (and currently is introducing an extra overhead). According to Borland help, integer and cardinal are generic types which are mapped to processor type. That means they will be 64 bit on 64 bit compiler.
Am I wrong here?
In the same way I tried to make some other constants independent of compiler version (32/64 bit). Please tell me anything which doesn't look right.
It's posted back to attachments, including a dummy test.
Gabriel
.
- Follow-Ups:
- Re: Object Creation (was objpool) again
- From: Eric Grange
- Re: Object Creation (was objpool) again
- Prev by Date: Re: Fastcode Template B&V's
- Next by Date: Re: Object Creation (was objpool) again
- Previous by thread: Class Size Creation Statistics
- Next by thread: Re: Object Creation (was objpool) again
- Index(es):