nasa / bplib

Apache License 2.0
27 stars 13 forks source link

Implement block-type registration API #92

Closed jphickey closed 2 years ago

jphickey commented 2 years ago

The "mpool" memory pool implementation in the v7 code uses a signature value to indicate a class of user content. Each block has a major type defined in the mpool, which serves as a "base class" conceptually, and the signature identifies the sub-type or "derived class" that extends that with application-specific information.

However, an important missing feature is the concept of a "virtual destructor" -- at any point during processing, if a block cannot be processed and is dropped for whatever reason, the block needs to be reliably cleaned up. The generic clean-up code only knows how to clean up the base type. If the derived/user part also had references/pointers to other blocks, this will not be cleaned up. This is similar in concept to the virtual destructor in a C++ class, where if a reference to a base class is deleted, the destructor of the derived class will be invoked.

A similar functionality can be achieved by pre-registering the signature value, which can also provide an api for constructing/destructing the objects. This has the added benefit of catching any block type value collisions should they occur.