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?

You 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*, some_data> m_mMemoryMap;
};

Of course this code won't compile and a lot more sanity checking should be done.. but its just an idea.

So you actually store a pointer, not the actual object.

Thanks a lot

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.