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: - typedef std::map<MyDataKey*, MyInfo*, MyLessThanFunctor> My_Map;
and my find code: - 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.
6 2409
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.
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.
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.
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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...
|
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 ; //...
|
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)
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"....
|
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...
|
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: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
| |