- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]#include "tbbscalable_allocator.h" #includeThe output of the program with Intel C++ Release: is "Called my delete" (and a crash) while the output in Debug mode and in MS C++ is none (meaning that none of my operators is called).#include using namespace std; void* operator new (size_t size) throw (std::bad_alloc) { cout << "Called my new" << endl; if (size == 0) size = 1; if (void* ptr = scalable_malloc(size)) return ptr; throw std::bad_alloc(); } void* operator new[] (size_t size) throw (std::bad_alloc) { cout << "Called my new[]" << endl; return operator new (size); } void operator delete (void* ptr) throw () { cout << "Called my delete" << endl; if (ptr != 0) scalable_free(ptr); } void operator delete[] (void* ptr) throw() { cout << "Called my delete[]" << endl; operator delete (ptr); } // I omit the non-throwing versions, but they exist int main() { string str("A test string. A test string."); return 0; } [/cpp]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1. what version of icl?
2. are you using TBB from the Intel C++ Compiler package? or you have downloaded a different version?
3. compile options?
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1. what version of icl?
2. are you using TBB from the Intel C++ Compiler package? or you have downloaded a different version?
3. compile options?
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>t_icl_Od.exe
>>
>>t_cl_Od.exe
>>
>>t_icl_o2.exe
Called my new
Called my delete
>>
>>t_cl_o2.exe
>>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]ifstream file ("Test.txt", std::ios_base::in); string line; getline(file, line, 'n'); [/cpp]With the following compiler settings:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Then disable inlining just for that single function. D'oh!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Then disable inlining just for that single function. D'oh!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The behavior of the Microsoft compiler depends solely on whether
or not the standard library is linked in dynamically or statically,
i.e. with /MDd the new/delete operators are not overridden but
with /MTd they are.
The Intel compiler behaviour depends both on dynamic/static linking
and whether certain optimizations like inlining are enabled.
With static linking (i.e. /MTd) our behavior is the same as
Microsoft's - the functions are overridden.
So perhaps an acceptable workaround would be to link in the
C++ standard library statically?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try adding __declspec(noinline) in front of the function definition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So perhaps an acceptable workaround would be to link in the
C++ standard library statically?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try adding __declspec(noinline) in front of the function definition.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unfortunately sometimes it can help, and sometimes not like in your case. Hopefully it would be fixed soon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This issue is being worked on. The coming Intel C++ Compiler for Windows update 5 will not contain the fix. Sorry about this.
I'm still waiting to see if it's possible to fix in the update after update 5. I'll let you know when there's more news.
Right now the work-around is to use the debug libs or use /Ob1.
Like:
C:\test\
>>icl /O2 /Ob1 /EHsc /MD new-t.cpp
Intel C++ Compiler Professional for applications running on IA-32, Version 11.1 Build 20091130 Package ID: w_cproc_p_11.1.054
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.
new-t.cpp
Microsoft Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.-out:new-t.exe
new-t.obj
C:\test\
>>new-t.exe
Called my new
TEXT: This is a testing. ***
Called my delete
C:\test\
Thanks,
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's another work-around using "/Qinline_dllimport-", see below.
Both /Ob1 & this option may have performance impact.
C:\test
>>icl /O2 /Ob2 /EHsc /MD /Qinline_dllimport- new-t.cpp
Intel C++ Compiler Professional for applications running on IA-32, Version 11.1 Build 20091130 Package ID: w_cproc_p_11.1.054
Copyright (C) 1985-2009 Intel Corporation. All rights reserved.new-t.cpp
Microsoft Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.-out:new-t.exe
new-t.obj
C:\test
>>new-t
TEXT: This is a testing. ***
C:\test
>>
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
did you see my response on "March 8, 2010 10:25 AM PST"? I didn't get your response so checking again.
Also I posted a work-around on "February 12, 2010 7:49 AM PST".
Did you seethose responses? Could you let me know? We're unable to duplicate the crashwhen using/MD.
Thanks,
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
About this issue, after our compiler engineer's investigation, it is not something can be fixed in the compiler.
In the Windows environment, in a program that is built using DLLs, replacing global operators new and delete is at best a chancy operation, because a replacement new/delete that’s provided in one DLL (or the main program) doesn’t necessarily replace all the uses from other DLLs.
So it’s possible to allocate memory using an operator new from one DLL, then later try to deallocate that same piece of memory using an operator delete from a different DLL. If those different functions from different DLLs happen to use the different underlying memory allocation/deallocation scheme then the program is very likely to fail.
This problem is inherent in the Windows dynamic-linking model, and can occur with Microsoft’s compiler too.
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page