# Using a pointer as a HashMap's key

**URL:** <https://forum.juce.com/t/using-a-pointer-as-a-hashmaps-key/7261>\
**Category:** General JUCE discussion\
**Created:** [August 5, 2011, 8:56am UTC](https://forum.juce.com/t/using-a-pointer-as-a-hashmaps-key/7261 "2011-08-05T08:56:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shlomi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shlomi/32/99_2.png) [@Shlomi](https://forum.juce.com/u/Shlomi)\
**Post date:** [August 5, 2011, 8:56am UTC](https://forum.juce.com/t/using-a-pointer-as-a-hashmaps-key/7261/1 "2011-08-05T08:56:40Z")

</div>

Hi.

I’m using a HashMap with pointers to MidiMessage:

```auto
    HashMap <MidiMessage*,int> notesOffIdHash;
```

And I get this warning message:

```auto
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

```auto
    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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 5, 2011, 9:23am UTC](https://forum.juce.com/t/using-a-pointer-as-a-hashmaps-key/7261/2 "2011-08-05T09:23:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Shlomi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shlomi/32/99_2.png) [@Shlomi](https://forum.juce.com/u/Shlomi)\
**Post date:** [August 5, 2011, 9:52am UTC](https://forum.juce.com/t/using-a-pointer-as-a-hashmaps-key/7261/3 "2011-08-05T09:52:37Z")

</div>

Hmm… that changes things… thanks!
