Overriding malloc()

asked 2016-03-10 12:28:53 -0600

fijoy gravatar image

Hi all,

I am in the process of integrating OpenCV into a large code base (100K+ lines). To track and control memory usage, I'd like to override all memory allocation and deallocations by OpenCV. I understand that I can override the new [] operator to partly achieve this goal.

However, OpenCV source also relies on malloc() calls. My research shows me that the easiest way to override malloc() calls is to use pre-processor macros like the one below since there is no portable way of overriding malloc (e.g., malloc hooks only work in Linux).

define malloc(X) my_malloc((X))

However, the macro option obviously will not work for pre-compiled binaries. My question is this: does OpenCV use any pre-built binaries that may be calling malloc()?

Thank you, Fijoy

edit retag flag offensive close merge delete

Comments

I don't understand how #define will change link entry point in dll.

If it's possible you have to build yourself opencv using cmake ( 10 minutes)

LBerger gravatar imageLBerger ( 2016-03-10 13:38:39 -0600 )edit