Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Welcome Guest | Log In | Register | Benefits
Channels ▼
RSS

Creating STL Containers in Shared Memory


Listing 3: A container factory

Listing 3: A container factory

struct keyComp {
    bool operator()(const char* key1,const char* key2)
    {
        return(strcmp(key1,key2)<0);
    }
};
class containerMap: public map<char*,void*,keyComp,SharedAllocator<char* > > {};
class containerFactory {
    public:
        containerFactory():pool_(sizeof(containerMap)){}
        ~containerFactory() {}
        template<class Container> Container* createContainer
            (char* key,Container* c=NULL);
        template<class Container> Container* getContainer
            (char* key,Container* c=NULL);
        template<class Container> int removeContainer
            (char* key,Container* c=NULL); 
    private:
        Pool pool_;
        int lock_();
        int unlock_();
};


Related Reading


More Insights