Using a pointer as a HashMap's key


#1

Hi.

I’m using a HashMap with pointers to MidiMessage:

    HashMap <MidiMessage*,int> notesOffIdHash;

And I get this warning message:

d:\project\sdks\juce\juce_amalgamated.h(10963): warning C4800: 'juce::MidiMessage *' : forcing value to bool 'true' or 'false' (performance warning)
1>          d:\project\sdks\juce\juce_amalgamated.h(10962) : while compiling class template member function 'int juce::HashMap<KeyType,ValueType>::generateHashFor(juce::MidiMessage *) const'
1>          with
1>          [
1>              KeyType=juce::MidiMessage *,
1>              ValueType=int
1>          ]
1>          d:\project\client\source\tester.cpp(64) : see reference to class template instantiation 'juce::HashMap<KeyType,ValueType>' being compiled
1>          with
1>          [
1>              KeyType=juce::MidiMessage *,
1>              ValueType=int
1>          ]

So instead of creating a special generateHashFor(juce::MidiMessage *) I changed the hashmap to

    HashMap <uint32,int> notesOffIdHash;

And just casted everything to uint32.
I know it’s lazy but is that the right approach regarding pointer keys with HashMap?

Thanks


#2

Pointers are not hashes! If you delete a midimessage, then its old address may be re-used next time you allocate another different one.


#3

Hmm… that changes things… thanks!