Recent

Author Topic: What is the difference between the new ADVANCED RECORD and the old OBJECT?  (Read 23679 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 745
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #60 on: October 22, 2021, 12:46:50 pm »
A class / object / advanced record is basically a block of memory with an index to show where the different parts reside. Methods are just functions / procedures that have an invisible @self pointer as first parameter. So, nothing is stopping you to allocate simple records on the stack and access them through pointers. In the past, before classes existed, I put all of the parts in linked lists, so it was easy to inherit and with an optional index to access the larger ones faster. Which is basically what a modern class is, although the compiler magic hides the pointers and packs them into arrays.

PascalDragon

  • Hero Member
  • *****
  • Posts: 3521
  • Compiler Developer
Re: What is the difference between the new ADVANCED RECORD and the old OBJECT?
« Reply #61 on: October 22, 2021, 03:51:43 pm »
Btw, @Serge writes constructor Init and not constructor Create in the records. I think it's probably to disconfuse between "constructors", whether it is an object instance (Create, i.e. located in the heap) or an advanced record variable (Init, i.e. located in the stack).

You can name the constructor method any way you want, even for classes. The only exception is if you want to override an existing constructor then you need to use the same name, but otherwise you're free to use Init in a class as well.

So, as far as I understand, nothing magic in memory allocation, including with this advanced records and their "constructor Init" (that said, it - the compiler - still does a lot of work for us in the background to automatically manage a specialized "type safe" container-list-map-..., even with these advanced records).

That management indeed has nothing to do with advanced records or not, it's simply related to whether you use e.g. AnsiString, Variant or IInterface.

 

TinyPortal © 2005-2018