[fpc-devel] Pointer cache for fast class/pointer access.

Hans-Peter Diettrich DrDiettrich1 at aol.com
Wed Jan 4 19:14:35 CET 2012

Sven Barth schrieb:

>> And, as somebody asked, what the advantages (performance?) using
>> Object instead Class?
> They are basically similar to "records with methods" (which we now have 
> as well...) if you use them directly (this means: not as pointer types): 
> they are located on the stack and nested objects are part of the memory 
> structure of the object.

To clarify "nested": object types can inherit from other objects, like 
TObject can do - that's an advantage over records. They even can emulate 
multiple inheritance, because (as you pointed out) contained objects 
become part of the composed object, do not reside in a different (heap) 

> But if you use references to objects you work 
> more like with classes as you have constructors, virtual methods and the 
> objects are then located on the heap (thus you need to care for the 
> memory management yourself).

Objects with virtual methods must not necessarily reside in the heap. A 
VMT reference is inserted into the object, as soon as the first virtual 
method is added. This leads to VMT pointers which do not reside at the 
begin of the instance memory, similar to interface references. OTOH the 
VMT (classtype!) reference at the begin of *every* TObject allows for 
"is" and "as" operators (RTTI).


More information about the fpc-devel mailing list