[fpc-devel] Suggestion: reference counted objects
Ewald
ewald at yellowcouch.org
Mon Sep 22 22:09:49 CEST 2014
On 09/22/2014 08:28 PM, Boian Mitov wrote:
> In general, records and classes are inherently the same thing (and in
> C++ are indeed practically interchangeable). The only real difference
> in Delphi/FPC is that records are instantiated in the stack,
Or on the heap:
==========
Type
TMyRecord = Record
End;
PMyRecord = ^TMyRecord;
Var
a: PMyRecord;
Begin
a:= GetMem(SizeOf(TMyRecord));
End;
==========
> the objects in the heap,
If you alocate them like
==========
Type
TMyObject = Object
End;
Var
a: TMyObject;
==========
`a` will be on the stack, not on the heap. I you allocate them using
`New`, they will be on the heap.
See, that is what I love about this language and this compiler: you can
do whatever you want! You want to write assembly: go ahead, wanna think
higher level: you get a wonderful assortment of available primitives:
- Dynamic arrays/strings
- Static arrays/strings
- Records
- Objects
- Classes
- Interfaces
Al with their own unique flavour. It is a bit like two programmer
programming assembly:
- One prefers a RISC style instruction set because it is composed of
a set of primitive instructions that are easy to comprehend, the CISC
instructions are complex and have many pitfalls is what he/she says.
- The other programmer says programming RISC is a drudgery:
constantly writing the same instructions that do nearly nothing, have no
special side effects, all the fun is gone.
As a programmer, pick the patterns you like, use them as much as you
think is appropriate and know when they are not. In pascal you can do
that because of the above.
So much for my little praise to pascal :-)
> and the artificial restriction on record inheritance.
If you want a record with inheritance, use object.
--
Ewald
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140922/4b3c5d75/attachment.html>
More information about the fpc-devel
mailing list