[fpc-pascal] operator overloading and counting references / creating / destoying anonymous instances

Sven Barth pascaldragon at googlemail.com
Fri Jul 29 11:39:23 CEST 2011


Am 28.07.2011 23:04, schrieb Mark Morgan Lloyd:
> I wonder if I could ask a silly question here, without displaying too
> much ignorance.
>
> I generally understand the significance of an interface in the Windows
> context, where COM (or whatever today's name for it) is integrated
> fairly deeply into the OS.
>
> But what of other OSes like Linux? Does the use of interfaces as a way
> of getting refcounted storage assume the presence of CORBA etc., and how
> much overhead is there at program startup- does it demand that an ORB be
> loaded into memory?
>

While COM-interfaces in Delphi/FPC are designed to be Delphi compatible, 
they do not rely on COM. Basically a IInterface or IUnknown is simply an 
interface that contains calls for increasing/releasing a reference 
count. You as the implementor of the interface need to provide the 
implementation. So e.g. TInterfacedObject which implements IInterface 
implements a reference counting mechanism where the object is freed when 
the reference count reaches zero. In FPC/Delphi this reference count is 
normally controlled by the compiler by calling the methods of IUnknown, 
but in C/C++ these calls need to be done manually (AFAIK).

CORBA-interfaces as implemented by FPC are just plain interfaces without 
any methods defined. Also the compiler does not generate code to 
influence the reference count as it does with COM-interfaces.

Basically an interface in FPC/Delphi is something that allows you to use 
certain methods (those provided by the interface) without knowing what 
the implementing class does. The COM-interface just contain a bit more 
compiler magic, but that's it.

So no, you don't need an ORB or something like that.

Regards,
Sven

PS: There is also a third kind of interfaces called dispinterface that 
contain again more compiler magic and are indeed used with COM 
automation (or XPCOM on non-Windows).



More information about the fpc-pascal mailing list