This is the mail archive of the
mailing list for the newlib project.
user defined malloc
- To: newlib at sourceware dot cygnus dot com
- Subject: user defined malloc
- From: "Ashif S. Harji" <asharji at plg2 dot math dot uwaterloo dot ca>
- Date: Mon, 3 Jul 2000 20:32:15 -0400 (EDT)
I originally posted a message to the cygiwn mailing list and it was
suggested that I also post it here. The original message is included
Basically, I am trying to find out if it is possible to provide my own
version of malloc? If so, does this also require _malloc_r to be
overriden (see message below?. And finally, if someone can provide some
information or a link on what is required to override _malloc_r (if it is
Original message to cygwin mailing list:
Subject: user defined malloc
It mentions in the faq that it is possible to override the default malloc
routine. The problem that I am having is that there is at least one
occasion when my malloc routine is not called for memory allocation.
Instead the function _malloc_r is called directly. This by passes my
malloc which results in already allocated memory being reallocated.
This direct call to _malloc_r occurs in the __sfmoreglue function in the
struct _glue *
__sfmoreglue (d, n)
struct _reent *d;
register int n;
struct _glue *g;
g = (struct _glue *) _malloc_r (d, sizeof (*g) + n * sizeof (FILE));
if (g == NULL)
p = (FILE *) (g + 1);
g->_next = NULL;
g->_niobs = n;
g->_iobs = p;
memset (p, 0, n * sizeof (FILE));
While I am not sure exactly what this function does, it appears to be
related to opening the /etc/passwd file and occurs even with an empty C++
My question is do I have to also override the _malloc_r routine, and if
so, could someone provide some information or a link on what is required?
It appears to be a reentrant version of malloc.