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

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Fri Jul 29 12:11:15 CEST 2011


Sven Barth wrote:
> 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).

So if I understand you correctly, use of interfaces does not imply use 
of OS or ORB facilities, but can permit it if required.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list