Wow, they really distorted the documentation, right? (I wrote this code when I was on Dinkumware)
Distributors are policy based here: you can specify a caching policy and a synchronization policy.
The basic idea is to simplify the writing of allocators that use internal caches and can be synchronized across streams. There are half a dozen predefined dispensers; their names begin with allocator_ . Use them if they suit your needs. In MSDN, consider the first paragraph of a specific dispenser description; do not read the "Notes" where they talk about ALLOCATOR_DECL
You can also use this code to create custom allocators that use predefined cache strategies (templates whose names begin with cache_ ) and synchronization strategies (templates whose names begin with sync_ ), or that use your own cache template and synchronization template. Getting a useful allocator from these parts is a bit tedious, so the header provides ALLOCATOR_DECL as a convenient way to create all the necessary templates without having to write it yourself. ALLOCATOR_DECL takes three arguments: the name of the cache template to use, the name of the synchronization template to use, and the name of the allocator you are creating. Therefore, instead of writing
template <class T> class name : public Dinkum::allocators::allocator_base<T, sync<cache > > { public: name() {} template <class U> name(const name<U>&) {} template <class U> name& operator = (const name<U>&) {return *this; } template <class U> struct rebind { typedef name<U> other; }; };
you will write ALLOCATOR_DECL(cache, sync, name); . allocator_base makes a heavy lift; the dispenser itself must be derived, so it can correctly handle rebind . ( Dinkum in this code comes from the Dinkumware documentation, I donβt know what namespace the Microsoft stuff contains, but presumably the macro puts the correct name there).
For cache templates:
cache_freelist maintains a linked list of node blocks; the maximum size of the list is set by the Sz template parameter, and the node is controlled using operator new and operator delete .cache_suballoc adds another layer that controls the block of Nelts node blocks, all allocated as one blob; highlighting a new item first refers to the free list, and if there is nothing free, a new blob is highlighted. The memory blocks are not deleted until the allocator is destroyed.cache_chunklist allocates memory in blocks (for example, cache_suballoc ), but does not use a common free list; when the block is released, it returns to the free list for its blob. When all blobs blocks have been freed, the blob itself will be deleted.
source share