"Alf P. Steinbach" <
alf.p.s...@gmail.com> writes:
>On 23 Sep 2021 16:46, Ayush Anshul wrote:
>> Consider me a C++ noob and go easy on me :|
>>
>> Suppose I have a package code and a product code on top of it.
>> I have control only over the package code side of things. My
>> memory is allocated/monitored via product code. Can
>> I override new/malloc on my side to get all allocations done via
>> that product code function or something similar
>>
>> One way I know is that they override global new/malloc on their end.
>> Other way is I write custom allocator, and use it everywhere(where I
>> have there allocator function registered as a callback).
>>
>> Is there some other easier way?
>>
>
>At the C++ level you can define `operator new` and `operator delete`
>(plus array variants) in each class.
>
>For a Windows DLL you can override `malloc` internally in the DLL, but a
>Unix shared library is more like a static library, not separate from the
>client code, so you can't do that with a shared library.