Hello. Maybe it would be better to state the real problem here, because I can't formulate a better topic title @_@ (sorry guys!)
I'm coding my GUI system right now, and so far it's been so simple:
-user create gui (sys->createGUIobj()) blah blah and return pointer to the created GUI object (which could be window, button, label)
-since user got direct pointer, he could do input by sending message to that object
the GUI objects are stored inside a hierarchy tree. which has root->children relationship. there's no concept of ID here, since each GUI object got its own pointer, and it is the user responsibility to store the pointer and then use it to communicate with them
now, I'd rather that the user set the GUI object's ID at creation, and make it so there's no need to store its pointer. he would just call
sys->settext(player_name_id, "FUUUUU") or whatever just by sending message supplying the GUI object's id. but then, I need a way to point to an object simply by using its ID.
I can't think about it other than using hash_map. I might use something like
hash_map<unsigned int, GUIObj*> obj_tables;
and access is very simple, just obj_tables[ID], see if it's NULL, which means it doesn't exist.
However, I did a simple test using vector, hash_map, and simple_array. it's just a stupid sample to see the insertion and access time of every construct type, and of course the simple array wins, but the main concern for me is that the average access time for the hash_map is the highest, being 0.415 ms in my notebook. (which means that for 1000 access it's 415 ms!!!) this is unacceptable to me, however, I can't find a better approach.
btw, here's the source code of the simple sampler app I wrote
Thus, I wonder how I would solve the problem.
I want to refer to an object just by suplying its ID (which is quite arbitrary since it's supplied by the user)