I’m using Visual Studio 2012 in Windows 7 64 bit.
I need to use concurrent data structures because I will be using threads. I found that microsoft has a few http://msdn.microsoft.com/en-us/library/dd504906.aspx#unordered_map
In general, I have to process
receive data into a queue…. process when ready … keep receiving data.
I’m going to use concurrent_unordered_map Class provided by microsoft to have a cuncurrent map that stores a class named TouchInfo.Each TouchInfo object has a unique ID (unsigned long) which is what I used to retrieve the object as it needs to be updated.
At the same time, I need to insert TouchInfo into a concurrent queue…
Once the queue hits a number I process the queue… (Different thread)
1.
My first question is if I need a special hash function of the unsigned long… The unsigned long is an ID (dwID) given by the system from the multi-touch system in Windows 7 (WinUser.h) Since I have no control of the ID, I want to make sure that my hash function is optimized.
typedef struct tagTOUCHINPUT {
LONG x;
LONG y;
HANDLE hSource;
DWORD dwID;
DWORD dwFlags;
DWORD dwMask;
DWORD dwTime;
ULONG_PTR dwExtraInfo;
DWORD cxContact;
DWORD cyContact;
} TOUCHINPUT, *PTOUCHINPUT;
Maybe, I don’t have to do anything and just declare
I seen in the web that some people use Boost to create the Hash…
Any input and changes in my design, are completely welcome…
The Answer to my question is most welcome!
Thanks!
concurrent_unordered_mapusesstd::hash, which has a default implementation forunsigned long. It’ll work fine right out of the box.The default hash tries to be optimal for most use cases, but there are no guarantees because everyone’s data is different. Definitely benchmark it before going crazy looking at hash functions (there are plenty, and you might waste lots of time).