[fpc-pascal] Class vs Object type
mailinglists at geldenhuys.co.uk
Wed Apr 6 13:23:01 CEST 2016
I use Class and Object data types frequently in my code. I like the fact
that Object data types can be used without first instantiating an
instance and it gets freed automatically.
But is there a technical (maybe compiler) reason why I should possibly
switch all my code to only using Class types for instance?
It has to be said that for more complex "objects" I always use a Class
type though. Also, Delphi compatibility (or their lack of Object type
support) is of no concern to me.
>From the FPC documentation I noted the following:
"The difference between objects and classes is mainly that an object is
allocated on the stack, as an ordinary record would be, and that classes
are always allocated on the heap."
Are there pros or cons to either?
- Graeme -
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
My public PGP key: http://tinyurl.com/graeme-pgp
More information about the fpc-pascal