Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2465 Discussions

Problem with automatic use of scalable_allocator on Windows

dan6
Beginner
288 Views
I've got an application with a number of DLLs and I've enabled the automatic replacement of malloc/free by including:
#include "tbb/tbbmalloc_proxy.h"
into the cpp that contains the WinMain for my application (i.e. cpp of my exe).
When I run in debug mode I get some RtlValidateErrors after this change, so I did some debugging and found that news/deletes called in global constructors in my dlls can before the patching of the mallocs bydoMallocReplacement which leads to mis-matching of memory allocation/deallocation calls.
Any solutions for this issue?
0 Kudos
5 Replies
Vladimir_P_1234567890
288 Views

Hi

this is unusual behaviour, memory which was allocated by standard crt should be deallocated by standard crt via forward from scallable_free/delete.
when do you get the errors, during realloc?
and which tbb version and runtime version do you use (arhitecture and dll name/version)?

thanks,
Vladimir

0 Kudos
dan6
Beginner
288 Views
It looks like the problem is that these news happen before tbmalloc redirection code takes effect. The reason for this seems to be that the DllCRTInitialization for these dlls runs before the same named routine for tbmalloc_proxy (which calls the redirection function AFAIK). DllCRTInitializationfor my Dlls calls CRT_INIT which initializes global objects in my dll and these global objects make calls to new. So these news happen before the redirection takes place.
I'm using the latest version of the tbmalloc code I believe (tbmalloc_debug.dll has file version 3.0.2011.704, for example).
If it would be helpful, I can probably create a simple test case that duplicates the problem I think.
0 Kudos
Vladimir_P_1234567890
288 Views

If it would be helpful, I can probably create a simple test case that duplicates the problem I think.

it would be great.

--Vladimir

0 Kudos
dan6
Beginner
288 Views
I couldn't duplicate it with a simple test case, so I went back and scoured the code base with the problem more thoroughly and I found some code that overrode the microsoft new/deletes already for some memory tracking reasons. The code wasn't really used anymore (it was only there for diagnostic purposes during development), but something about it's continued existence cause the problem. I removed these files from the build and it works now (although all my news/deletes still aren't being caught by the "automatic" header, unfortunately, so I'm still left to add new/delete overrides on many of my classes). So I guess this issue can be closed, assuming it's known that the "automatic" header doesn't override all news/deletes.
0 Kudos
Alexey-Kukanov
Employee
288 Views
The allocator replacement only overrides global new and delete operators provided as entry points by MSVCRT, but is unawareof any overloads. If you think your new/delete operations are global and should be overridden but aren't, please try making a reproducer and we will take a look.
Thank you for the feedback that helpsimproving TBB!
0 Kudos
Reply