Re: A re-announce on GC's defects

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Barry Kelly wrote:
Andre Kaufmann wrote:
[...]
Perhaps I've been programming C++ too long and can't get used to another programming style that easily ;-).
A C# developer coming from Delphi won't have such "problems".

Delphi Win32 users can also implement RAII, using interfaces.

Semantically this is comparable to C++ RAII. Though there are downsides using these interfaces, intentionally implemented to support COM, as a RAII replacement.

At function scope it's IMHO too much overkill, since the interfaced objects will be created on the native heap, instead being constructed on the stack as in C++. This would be a rather slow approach, for releasing resources at function scope commonly therefore try finally is used.

In .NET there isn't the same overhead as in Win32 in constructing objects. However a stack based approach would be IMHO faster, but C# has adopted the Delphi style and added the "using" keyword.
No big deal, though sometimes I'm missing RAII and assignment operator overloading or some approach of automatic resource handling.

If you ignore the runtime overhead for object construction in Delphi.W32, then I agree that you can use interfaces as a RAII replacement.

Interfaces
in Delphi are ref-counted COM-style interfaces, implemented behind the
scenes a lot like CComPtr<T> and friends.

Yes, but IMHO the internal implementation of interfaces is hidden too much. They are perfect if you don't mix them with other objects, e.g. hold them in the same object list. Otherwise I'll promise a developer doing this having much fun ;-).

-- Barry

Andre

.



Relevant Pages

  • Re: Delphi 8 vs Visual Studio
    ... Oh you can have it, in Win32, using guard interfaces. ... But RAII is not a very useful Delphi idiom, ... And switching between managed and unmanaged mode seems to be quite a loss ...
    (borland.public.delphi.non-technical)
  • Re: A re-announce on GCs defects
    ... programming style that easily;-). ... Delphi Win32 users can also implement RAII, using interfaces. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delphi interfaces vs. COM interfaces
    ... > some traditional class-based Delphi code. ... I have a CoClass and an interface. ... If you design the Delphi class to actually implement interfaces, ... > other Delphi classes, so these would in turn have to be access via ...
    (borland.public.delphi.language.objectpascal)
  • Re: Von Delphi nach C#
    ... die Instanz, sondern lediglich eine syntaktische Eigenheit, die diese ... IYO Delphi "Interfaces als eigenständige Objekte" ansehen soll. ... Das soll Delphi ja auch nicht. ... gleicher Syntax) ein paar Eigenheiten mit sich, ...
    (de.comp.lang.delphi.misc)
  • Re: C#Builder 2007(2008)
    ... than C++ RAII. ... "Resource Acquisition Is Initialization" ... their destructors can do things like ... It is similar to guard objects using interfaces in Delphi, ...
    (borland.public.delphi.non-technical)