[fpc-pascal]Class Identification?

Sebastian G√ľnther sg at freepascal.org
Mon Mar 24 14:01:50 CET 2003


On Mon, 2003-03-24 at 18:17, Anton Tichawa wrote:

> Nor did I - Thank you. I'd like to ask several questions:
> 
> 1. What is then the difference between a class without ancestor, and a class 
> inheriting from TObject?

There is no difference


> 2. Will TObject remain the "default ancestor" in the future?

Yes


> 3. Efficiency: Sometimes I use classes without ancestor, with the assumption, 
> that this might be more efficient in cases where TObject's methods and fields 
> are not necessary. It seems that assumption was wrong. To save resources, 
> should I use explicite pointers to objects when I don't need the features 
> inherited by the class TObject?

No, I won't use classes in such cases. You could use objects (i.e. use
the old object model introduced in Turbo Pascal 5.5, instead of Delphi's
object model), they won't add any overhead. OTOH I don't recommend to
use the old objects anymore, because almost all new high-level units use
classes, and mixing classes with objects will lead to really ugly code.

The methods of TObject don't add overhead. The memory usage is very low
as well: Only a single pointer (VMT pointer), plus the data fields of
your class. But the VMT data has to be stored in the executable,
including some relocations. Constructing and destructing of TObject
instances is somewhat slower that for the old objects, but I think you
can neglect this in almost all cases.


- Sebastian




More information about the fpc-pascal mailing list