I`ve run into a problem with the malloc proxy and static variables (MSVS 2008, Win7). The problem is that tbb replaces memory allocation routines when the DllMain function is run, but this happens after the static variable initialization phase and they use the default allocation functions, but when the program finishes those static variables are destroyed with substituted routines, which sometimes leads (i wonder why not always?) to a crash. The program is most likely to crash when the static variable aquired some kind of resource (file or something else) during initialization and kept it until the program has finished. I think that if we want malloc proxy to work correctly, we must revert the memory function substitution done in DllMain when the dll is being detached from the process(it happens before static variables are destroyed), so that static variables could deallocate the memory using the same functions with which that memory was acuired.
which tbb version do you use? 2.2 update 1 andnewer should have better support for the windows malloc replacement including static objects support improvements.
I`ve looked into the proxy.cpp file from the develepment release 20091101 and it seems to save the addresses of original free() functions, but i dont get when and where these functions are replaced back. Could someone explain it please?
Is this the 64-bit system? There is known issue with crash on application exit on 64-bit vista or win7 for this development release. If yes pls take the newer package.
Original functions are not replaced back. Even after final call of DLLmainproxy libaryis not unloaded and replaced functions can be called and executed.
BTW in your case you cannot use realloc to resize data structures in static objects in the middle of the program.
Could you please tell me what you did to get rid of the crash? I run into the same situation (http://software.intel.com/en-us/forums/showthread.php?t=72457) and my app still crashes even after I tried to override the global new and delete operator with calls to scalable_malloc and scalable_free, totally bypassed tbbmalloc_proxy.dll and the function replacement stuff. I even exposed the isRecognized function as you suggested.
After I made this change (link with tbbmalloc.lib directly, bypassing tbbmalloc_proxy.dll and memory function replacement), my app crashes HARD with access violation in the C runtime FreeHeap function.
Thanks for your help.