Edit: Delphi 2009 includes the generic TList<T>
, I assume it's implemented using array of
, just as the one in Delphi 2010. That makes the TList<T>
the optimal choice! My original answer stays because it explains why array of
is a great data structure and why not using it is a lot of trouble.
Your choice of array of Anonym
looks very good to me because:
- Anonymous methods are managed entities (implemented using interfaces). They need to be properly finalized.
- The dynamic array is itself a managed type, making sure the anonymous method references are properly finalized.
- Delphi 2010 generic containers are implemented using dynamic arrays, so they're up to the task. But make sure you don't grow your arrays one-by-one, grow in chunks.
If you use anything else for the implementation you'll need to take care of finalizing the references yourself. Examples:
- If you use plain blocks of memory you'll need an destructor that deliberately sets each item to nil (ie: not ZeroMemory or FillChar) so the compiler gets a chance to generate finalization code.
- Records are managed objects, and they could hold references to dynamic methods, but they can only hold a finite number of references, if you need more you'll need to implement a sort of linked list and then you'll need to carefully manage there life cycle.
- Classes suffer all the deficiencies of records, and they add their own layer of overhead on top of that.