Hello,
I have a hash map with int as a key and struct myStruct as the data.
I got to the conclusion that I shuold have a pointer to the struct since I have some copy operation,
this is how I define my table:
typedef std::hash_map<int, myStruct*> myStructTable;
myStructTable m_MyTable;
I have a loop that on compilation time, number of iteration is unknown. (loop on std::list)
on this loop I create on every iteration MyStruct
should I create it on advance as pointer to myStructTable and allocate it with a new
or can I creare MyStruct itself and put its address in the table
what I mean:
option 1: (no need to worry about deallocations)
for(;;)
{
MyStruct myStruct;
....
//my struct initialization
m_MyTable[key] = &myStruct
}
option2: (deallocate my hash_map items at the destructor (m_MyTable is a class member)
for(;;)
{
MyStruct *myStruct;
....
//my struct initialization
m_MyTable[key] = myStruct
}
thanks