Monday, 19 April 2021

Modern day Record Handling with C++

Record Handling analysis

Record Handling by C.A.R Hoare introduced the notion of objects as records.

Key features

  • Garbage collection through reference counting.
  • References for compositing functional relationships.
  • Dynamic allocation so objects can outlive their block.
  • Create and Destroy procedures for creating objects (anywhere in the program) and removing them.

C++

In modern C++ the record handling features above are possible.

Feature C++ Java
Garbage collection std::shared_ptr Built into the JVM.
References std::shared_ptr All objects are reference types.
Dynamic allocation
  • Per class custom allocator to prevent fragmentation
  • use of 'new' wrapped in a std::shared_ptr
All objects are dynamically allocated.
Create and destroy procedures 'new' and 'delete' 'new' provided but no explicit destroy procedure.

Example


Notes

C++ is prefereable to Java because not all objects require the record handling features. A large portion of programming does not deal with true "objects" in the sense that record handling denotes, therefore by using C++ and C we can efficiently control the machine and only optionally invoke the record handling features when required.

Friday, 16 April 2021

OOP without the heap

Safety critical software standards forbid dynamic memory however OOP is desirable when designing an embedded system. OOP can be used without dynamic memory by preallocating space for the objects at a suitable location and creating references to them. References are mandatory for OOP however the heap can be avoided.

Modern day Record Handling with C++

Record Handling analysis Record Handling by C.A.R Hoare introduced the notion of objects as records. Key features Garbage collection t...