Search code examples
c++windows-phone-8malloc

How to integrate dlmalloc in a Windows Phone 8 c++/cli application


I'm attempting to integrate dough lea's malloc (malloc.c) into a native WP8 app.

Adding the dlmalloc.c file to the MVS 2012 for Windows Phone results in a "cannot compile malloc.c with the /ZW option" error. Following this post I got rid of that problem.

Then I got rid of the EINVAL and ENOMEM undefined errors by including errno.h at the start of malloc.c

But now I'm stuck with different variations of:

error C2375: 'malloc': redefinition; different linkage (in file stdlib.h)

(for malloc, calloc, free and realloc)

I tried setting the NO_MALLOC_STATS for the dlmalloc to stop the include of stdlib.h but that didn't seem to solve it, as well as #undef-ing calloc.

Has anyone tried integrating dlmalloc in a wp8 app? If so, am I going the right way about it?

Thanks,

Jaime


Solution

  • For the record, the last step missing was adding

    "#define USE_DL_PREFIX"

    At the top of the file, to use the dlmalloc, dlfree,... names instead of malloc, free, and so on.

    Once that was done, I was able to use dlmalloc and the rest in my code.