Hi, I need a container which has multiple keys. The number of keys,
which are related to a value, is not constant, but it is small. (less than 10)
I have tried to do this with std::map, but things are working only with a
constant number of keys per value. Any suggestions?
I have used the previous one, where I have map of pointers, but I have some
problems. This map is, of course, member of a class. But I might have some
memory problems. When I fill the map with keys and values everything seems
to be working, (i print everything and everything is there) but when I do
something else with the map afterwards, for example, at the end of the
program, then pointers are pointing somewhere else. I just want that
pointers are pointing to the same object until they are destroyed.
void run(){ // Member of a class
void read();
// If I have function that uses a lot of memory here. My pointers
// are pointing somewhere else.
void high_memory_consumption();
void do_staff_with_the_map();
// If the same function is here, everything works.
// void high_memory_consumption();
}
Ok. Thanks but it didn't helped. As I said before I have printed the map at the end of the ( read() ) function and it is ok. But when I am printing the map in the function do_staff_with_the_map() pointers have gone wild.. Storage and map are constant after I have created these. I only have to read constant data from the objects. At least for me this is weird because high_memory_consumption() function has nothing that is related to the map or storage and If I remove that everything works.
read() function reads a file with some parameters and this map / storage structure should store basically most of the parameters, but not all of them. In the real case, when the code should work, I also need to pass couple of parameters ( just two integers and they are not stored in the map or storage ) from the read function to the high_memory_consumption() function. Now there is only fixed constants. Unfortunately I need to run functions in that order. Next I will try to use shared pointers. Let's see if it works.
It initializes some structures like matrices and objects which are members of the class. read, high_memory_consumption, do_some_stuff_with_map are all members of the class too.
You might be right. There might be something wrong in that function. After I commented this function
line-by-line i noticed that the problem disappears after a line. I try to solve this problem. Thanks!
Yes, Thanks for all of you! Especially for @JLBorges. I have no idea what was wrong but made some things differently and everything works now. Thanks again..