473,226 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

Odd map::find behavior on 64-bit windows

Been working on a project that compiles, links, and runs fine on 32-bit windows. Now trying to migrate to 64-bit windows. On debug build it works fine. However, on release build the std::map::find operation starts acting odd.

My code simply does a lookup, if it fails it inserts the proper element (creating the data element is expensive so I only want to do it if needed and many times its not). In the lookup I see the size is 0 (since release build relying on printf of .size ()). So I would expect to have .find return .end () that is nothing. Now my map is a map of ptrs so it uses its own comparator function, and the thing is I see the comparator called for the data i am looking for as well as a NIL ptr. This only happens in release build not debug, so strikes me as odd.

My map is defined as:

Expand|Select|Wrap|Line Numbers
  1. typedef std::map<MyDataKey*, MyInfo*, MyLessThanFunctor> My_Map; 
and my find code:

Expand|Select|Wrap|Line Numbers
  1. My_Map::iterator find_itr = m_my_map.find (key_ptr);
I verified the key_ptr address is one of the items in my comparator, but when the map size is 0 why is the comparator even called? Where is this NIL coming from and why only in release builds? Thanks for the help.
Jul 12 '07 #1
6 2408
weaknessforcats
9,208 Expert Mod 8TB
Obviously ,there is a difference between the 32-bit and the 64-bit templates.

Do you have the latest set of templates?? Dinkumware always seems to have fixes beyond the Visual Studio release.
Jul 12 '07 #2
This was first recorded using .NET 2003 compiler and includes. However to make sure I went with .NET 2005 compiler for this latest version and is breaking. I have been using google to try and track down the issue (can't be the only one seeing this if its a MS problem), but no luck. Can't use any custom versions here as this is for work and we must work with the standard .NET framework. I am also going o try as a test is creating another map and seeing what happens. A collegue also mentioned allocating large arrays on either side of my map allocation and then checking the contents of them to see if somebody is overwriting the memory and messing things up. Might be worth a try.

Also for further background this code works on Linux both 32 and 64 bit both debug and non-debug builds. So the evidence is mounting that there is something wacky on Windows 64-bit release builds.
Jul 12 '07 #3
Followup after a long day of debugging. The map in question was a class member of my object. I had some map::insert and map::find calls in methods defined in the header file. Once I moved these and all constructor/destructor code to the cpp files it compiled and ran fine. So it seems .NET 2003/.NET 2005 have problems when compiling in release mode with code in the header files. Works on every other build platform, so I'll chalk this up to an MS bug in the compiler.
Jul 12 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
So it seems .NET 2003/.NET 2005 have problems when compiling in release mode with code in the header files.
There should never be code in a header file. Header files are for declarations and .cpp files for definitions. Code in a header file will get you redefinition errors unless it has internal linkage, which means you need to use static, which is deprecated in C++, etc, etc... and it makes your footprint bigger.

By declaration I mean that no memory is allocated. No variables and no functions.
Jul 13 '07 #5
We do this all of the time for inline functions. Otherwise the compiler complains that the code is unavailable. We also only do it in methods of a class, which is supported by C++. If I tried this with actual functions outside the context of a class, you would be right there would be compile errors (same as if I declared globals in a header, multiple copies). But putting code in the methods is perfectly fine. Just not on Windows 64-bit Release builds apparently.
Jul 13 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
We do this all of the time for inline functions. Otherwise the compiler complains that the code is unavailable. We also only do it in methods of a class, which is supported by C++.
Inline functions are not function definitions. They are used by the compiler to copy inline where you call them, Functions inside classes are also inline functions. They, too, are copied as needed.

A function definition requires memory be allocated. An inline function allocates no memory so it is really more like a macro and, therefor, suitable, for a header file.

As to your problem, I did try your code on 32-bit Windows and there were no calls to the comparator. I tend to agree with you that it is an MS 64-bit compiler bug. You should report it.
Jul 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Matthias Hildebrand | last post by:
Hello, std::map< int, MyClass*> mymap; it = mymap.find( somekey ) // here happen bad things if( it != mymap.end() ) { // do something useful with it->second } else
3
by: Manuel Maria Diaz Gomez | last post by:
Hi everybody, This should be trivial, but I just can't see it. The following statement in a method doesn't work for me: (there's only one entry in myMap) map<const char*, int>::const_iterator...
13
by: jstanforth | last post by:
This is probably a very obvious question, but I'm not clear on what operators need to be implemented for std::map.find() to work. For example, I have a class MyString that wraps std::string, and...
3
by: rudymoore | last post by:
I'm often find-ing the same string in a map<string,xxx> I want to pass a hint to map::find but was disappointed to find that only map::insert takes the hint. Why would map::insert take a hint...
13
by: Peteroid | last post by:
Why does reading a member of a std::map not considered const? For example: class My_Class { int Get_Map_Value( int index ) const // ** error ** not considered const!!! { return m_Map ; //...
3
by: shaun | last post by:
I'm doing some work with const maps of various types and I find that I'm writing the same few lines of code over and over: (having declared and initialized a map<myTypeA, myTypeB> myMap) ...
5
by: subaruwrx88011 | last post by:
I am very new to c++ and very new to maps. Below is the source of my program. The output is very strange. Am I inserting correctly into the map? Any help will be greatly appreciated. #include...
17
by: devmentee | last post by:
Hello, I am trying to create a map/dictionary where the type of key is known ie std::string, but the value could be of any built in type. ie. int, double etc. (something along the lines of...
3
by: maheshr22 | last post by:
Hey Heres what i want to do: I want to create a map which has <string, vector<vector<int>>>. The string is always unique. What i need to do is, as i read each string from a file, i compare it...
12
by: Angus | last post by:
I am writing a class as a wrapper around a std::map. The class is: template<class TKey, class TValue> class CGeneralMap : protected map<TKey, TValue> At the moment I have basic functions like...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.