![]() |
Modules | |
Core Synchronization primitives | |
Core Threading primitives | |
Timer management | |
Opaque user data | |
Opaque user data is the name given to the concept of storing an arbitrary number of void * pieces of 'user data' in a class. The user of the class knows what the data is, the class itself doesn't care and, to it, the data is opaque. Generally the class that supports user data inherits from IIndexedOpaqueUserData and when it's created it has x 'slots' of user data created with it. Users of the class can then store their own things in the class. Classes that allocate objects that support user data generally inherit from IProvideUserData which allows the users to request a user data 'slot' and get given an index to it. Generally users request their slots before the first object that supports user data from this allocator is allocated (so all objects have the same number of slots!). Indices are allocated by name (and this is often the name of the class doing the requesting) so that there's no need for a central repository of information relating to how many user data slots each object needs to support. An example of this code in action can be seen in the IO Tools library with the IBufferAllocator and IBuffer interfaces and the Socket Tools library with the ISocketAllocator and various socket classes. The extensible nature of this design means that it's easy for code to be layered on top of the existing code that uses (and requires) user data in the sockets or buffers and for it to require as much or as little user data as it likes. |