NO

Author Topic: PellesC _msize fix  (Read 4719 times)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
PellesC _msize fix
« on: February 19, 2015, 06:40:28 PM »
This is not an addin, but there is no other section that exacly fit a compiler patch.
So a patch could be an adding to the compiler...
BTW these two simple files can be used to fix the brooken _msize of PellesC.

EDIT: This is upgraded version to make its use easier

How to use: Add the C file to your project, and include the header file to each module of the project, taking care to insert it just as the very first header even before of windows.h or stdio.h. This arrangement allow the correct redefinition of memory functions for all your code. Failing to do so can create mixed memory functions (especially when c modules are included) leading to crash-hangs.

How it works: the functions malloc, realloc, calloc, free and _msize are redefined to the routines in the C file. The patched routines add, for each allocation, an extra space for an unsigned 64 bits integer where it keeps the real allocation size.
I used a 64 bits variable not because such large counting was required, but because it is 8 bytes long and guarantee correct memory alignement for objects. Then the patched memory is passed through the conventional memory functions.
The disadvantage of this approach is that for each allocation are required 8 more bytes.

Caution! Be sure to apply the patch to all your modules, passing pointers got from patched routines to real crt functions, and the reverse, will give unpredictable results (normally crash  ;D)

PS: this can also be the start for memory profiling that wasn't available in PellesC ;D
« Last Edit: February 20, 2015, 02:46:48 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: PellesC _msize fix
« Reply #1 on: February 20, 2015, 02:47:42 PM »
I updated the code so you have simply insert the header as the very first header in your modules.
Download the new version from above.
« Last Edit: March 30, 2015, 09:53:00 AM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide