C ++: pointer as key in hash table

Are there any problems with using pointers as hash keys during program execution? (no need to store on disk and use it later, as this causes obvious problems)

There are many circumstances when I need to quickly find out if an object belongs to a particular object manager. A quick way to check this is to store each object in the object manager in a hash table, where the object pointer is the key to the actual object: for example, HashTable

+8
c ++ hashtable pointers
source share
3 answers

No, no problem. It is like saving int .

The pointer has a value that does not change and uniquely identifies the resource.

Of course, there are problems if you use your pointers poorly, but this is another, uncorrelated thing.

+5
source share

It should work well enough. Do you see any problems? Maybe you should just try and see. :)

0
source share

On top of my head. If the memory space that your hash table points to is freed without first deleting references to the memory space that your pointers point to, memory leaks will occur.

0
source share

Source: https://habr.com/ru/post/651162/


All Articles