A want to create some kind of global memory table.
Every time when I create a specific kind of object,
I wolud like to register it in the table, and save some data.
Let assume that this "memory table" is a map,
and a global variable.
Let assume that I have lots of objcets from the same class.
The constructor of these objects
creates a new data entry in the memory table,
and the destructor erase it.
I want that the objects can acces to the table and use it.
My problem is: what kind of map is good for me?
Because I dont want to copy the objects,
I just want to map: obejct reference (or pointer?) -> data
What is the syntax?
merse
0
Junior Poster
Recommended Answers
Jump to PostYou can create a map of "Specific Object" pointers.
E.g.:class CMemoryMap { public: void newObj( const CObject& myObject ) { m_mMemoryMap.insert( std::pair<CObject*, some_data>( &myObject, some_data ) ); } void delObj( const CObject& myObject ) { map_iterator = m_mMemoryMap.find( myObject ); m_mMemoryMap.erase( map_iterator ); } private: map<CObject*, …
All 2 Replies
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.