Op Tue, 5 Feb 2008, schreef Tiziano De Togni:

Michael Van Canneyt ha scritto:

On Tue, 5 Feb 2008, Tiziano De Togni wrote:

From the Delphi (7) help and in the borland newgroups I read that the old TP style object type is considered to disappear, and actually only kept for code
compatibility.

I see here that some developers still use the type object because of some
advantages against the Class type (static allocation).

Can someone explain better these advantages?

The advantage is mainly that you can have objects on the stack.

sorry, but don't understand exactly what this means exactly.

I understand that if I write a procedure of this kind:

procedure processmyobject(myobject: tmyobject);

procedure processmyobject(myclass: tmyclass);

I have myobject on the stack, instead myclass is passed by reference, but don't see the advantage...

Stack allocation is much faster than heap allocation, and automatic. Take a look at the matrix unit; you can return an object from a function without worrying about memory leaks, so they are very usefull in function results and operator overloading.

Further, objects allow you control the binary layout (the binary layout is just like a record), which means you can fit existing data structures (like those used in files) with methods. Some time ago we had a discussion about this list about mapping the GTK Gobject model to Pascal objects, succesfull experiments were done.

Daniël
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to