When a record has plain (non-managed) fields, like numeric or other enumerated values there isn’t much to do for the compiler and disposing the record consist of getting rid of the memory location and likely making it available to be reused later. Records can of course have fields of any type. These has deeper implications than it might seem. You can avoid the copy by passing the record by reference (var). By default, the compiler makes a copy of the entire record data. The other large difference we don’t have time to explore in full is what happens when you pass a record as parameter to a function. On the plus side, the way records are allocated in memory can help with memory management and make it faster as the memory is directly available skipping an extra allocation and deallocation operation. The core difference in memory layout is also related with the fact records lack virtual methods and inheritance, a key tenets of object-oriented programming. While a class based variable is just a reference to dynamically allocated memory, a record based variable has a copy of the actual data. The main differentiator from class type remains the way memory is allocated. In Modern Object Pascal (from Delphi 2009, if I remember) the record type constructor has gained many new features, from the ability to define methods to operators overloading.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |