Re: std::map

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks
std::string solves the problem so i dont need to use const char*
"Ashish" <akohli_2004@xxxxxxxxxxx> wrote in message
news:OUvQ6LLGJHA.2440@xxxxxxxxxxxxxxxxxxxxxxx
using std::string as key in map i dont need to overload any extra
functionality. map will be like
std::map<std::string, data>

But using const char* i need to add the functionality for key_compare and
allocator_type.
std::map<const char*,data,functionpointer,allocator> mapdata;
where functionpointer contains pointer to function which compare both keys
and allocator will allocate memory for key.
Because if i insert item in map like
mapdata.insert(std::make_pair("abc",data)); then
mapdata.find("abc") will return that item.
while if i insert item like
std::string str = "abc";
mapdata.insert(std::make_pair(str.c-str(),data)); then
mapdata.find("abc") will not return that item.
Since i cant save all keys in some class so i need to allocate memory for
each key in map itself.

Please suggest how to allocate memory for char* in map. If allocator_type
does this job then please give any sample how?



"Ashish" <akohli_2004@xxxxxxxxxxx> wrote in message
news:emAnpKJGJHA.1280@xxxxxxxxxxxxxxxxxxxxxxx
Thanks for reply
Yes if i use std::map<std::string, data> then it solves the problem.

I wrote data was corrupt when i use std::map<const char*,data>
it means if i insert one item in map with index "abc" and now if i search
that item by using mapname.find("abc") then it doesn't return that item.
When i check memory of mapname then it doesn't contains "abc" it first
place.

Well std::string solved the problem. But ifi want to use const char* then
please what what i need to do? should i create a new class derived from
map and override some operators/functions?





.



Relevant Pages

  • Re: std::map
    ... using std::string as key in map i dont need to overload any extra ... But using const char* i need to add the functionality for key_compare and ... and allocator will allocate memory for key. ... But ifi want to use const char* then ...
    (microsoft.public.vc.language)
  • Re: std::map
    ... But using const char* i need to add the functionality for key_compare and allocator_type. ... Because if i insert item in map like ... Since i cant save all keys in some class so i need to allocate memory for each key in map itself. ...
    (microsoft.public.vc.language)
  • Re: std::map
    ... But using const char* i need to add the functionality for key_compare and ... Please suggest  how to allocate memory for char* in map. ...
    (microsoft.public.vc.language)
  • Re: How do you decide what to code next?
    ... I tweak those as necessary as I add functionality. ... Right now I dump the game data into a text file. ... Map data, ... fov, los, and dungeon generation working. ...
    (rec.games.roguelike.development)
  • Re: Modification to asyncore.py to support threaded event loop
    ... 'module' object has no attribute 'map' ... asyncore does not have an attribute named 'map', ... Also, asyncore.loop has a while loop inside it, and you are adding ... > Module and/or functionality additions do not require a PEP (from what I ...
    (comp.lang.python)