From what I understand, classic objects, i.e. data structures declared with the
object keyword, take up the same amount of memory as their
record counterparts. We can declare such objects on the stack and on the heap, but unlike records, objects support inheritance. So they are something between records and classes, which gives additional possibilities, which I am happy to use.
In my game engine, I use such classic objects to create simple data structures that contain only fields with data (no methods) and this data can be inherited. Such objects can be used as local variables existing on the stack, but can also be allocated on the heap. When allocated on the heap, memory for them is always allocated using
GetMem and freed using
FreeMem. That's it in a nutshell.
Assuming that:
- objects contain only fields, no methods, constructors, destructors or properties,
- I use GetMem and FreeMem to manage their memory on the heap,
- if I use an object that exists on the stack, I never use New and Dispose functions.
can someone familiar with FPC internals officially confirm that using objects only with fields and not using the API dedicated to classic objects (constructors, destructors, New, Dispose etc.) makes such objects exactly the same as regular records? So far, I have not found that using them in the manner mentioned above would result in the automatic allocation of additional memory or forces the compiler to generate additional instructions.
Thanks in advance for your answers.