Ignore globally redefined new / delete

Hi, I am using the new / delete global override library. But I have a problem with this library, the problem is that it needs to be initialized manually in the main function.

Now I am trying to use another library that initializes several functions before calling main, unfortunately this library uses new ones in these functions. Therefore, I get errors because the memory manager that uses the overridden new / delete keywords is not yet initialized.

I would really like to use the default memory manager, because I want to add unit testing to this library. It would be inappropriate to use the memory used by my library that I want to test, also used by my Unit Testing library.

So my question is, is it possible to ignore the global overridden new / delete when the second library is included and just use the default new / delete?

I am using Visual Studio 2010 on Windows 7 with the standard C ++ compiler.

+7
source share
3 answers

I do not think that this is possible without changing the library itself. I assume this is a static library (inside the dll, the overridden new / delete will be indicated by the functions inside the dll.)

You can remove the obj file from the static library using the command (Visual command line):

LIB /REMOVE:obj_to_remove /OUT:removed.lib input.lib 

To find out which obj to remove, first run:

  DUMPBIN /ARCHIVEMEMBERS input.lib 

You will see lines like

  Archive member name at 14286: /0 compilation.dir\objfile1.obj 

14286 'identifies' the obj file. To see where each character is located, do:

  DUMPBIN /LINKERMEMBER:1 input.lib > members.txt 

and find new / delete. members.txt will contain the distorted names of each character and the identifier of the obj object in which this character is located. For example,

  14286 ?_Rank@ ?$_Arithmetic_traits@C @ std@ @2HB 

14286 tells you the identifier obj in which the character lies. If you are having trouble finding a new / delete, you can run:

  DUMPBIN /SYMBOLS input.lib > sym.txt 

which will be dumped in sym.txt distorted and incomprehensible names for each character.

obj_to_remove , delete the obj file using the LIB command above, replacing obj_to_remove with compilation.dir\objfile1.obj in our example and the link to removed.lib .

Now, if you're out of luck, the other characters you need may be in the same object file as the new / delete. In this case, you can β€œcrack” the lib using something like this (say, rename new to dew and delete to nelete .)

+1
source

Can you put the initialization of the memory manager from the main into a shared library?

If possible, you can try to force the initialization order of your libraries (depending) on ​​loading (and initializing) the memory manager before loading any other. This, however, is a very fragile (or specific) solution, as it will depend on workarounds for a particular platform in order to force the order in which shared libraries are initialized.

0
source

if overriding is done with a macro that you can use

 #pragma push_macro ("new") #undef new ...code with standard new here ... #pragma pop_macro ("new") 

If this is really done by overriding the function, you can temporarily create a β€œnew” macro yourself that calls the function with a different name, placed in a different place that just calls the standard function. Macros are allowed before function calls.

0
source

All Articles