* Number of bytes returned by malloc (or passed to free)?
@ 1995-03-04 12:08 cek
1995-03-05 16:12 ` Dan Pop
0 siblings, 1 reply; 4+ messages in thread
From: cek @ 1995-03-04 12:08 UTC (permalink / raw)
Does anyone know how to determine for OSF/1 on an alpha 3000 how many
bytes are actually allocated by malloc? I know this type of code is
non-portable and should not be relied upon but I only use it for
testing. I use it as a simple check for memory leakage by checking
the difference between the total bytes allocated by malloc and the
total bytes released by free. I am using OSF/1 V1.3 but will soon be
upgrading to OSF/1 V3.2
If anyone is interested, here is the SUN Sparc (4.1.3) version of what
I need:
In the code below, if memp is the pointer returned by malloc,
then size is the number of bytes.
#define ALIGNSIZE sizeof (double)
typedef struct MEMPTR {
unsigned size;
unsigned filler;
unsigned data [ALIGNSIZE];
} memptr;
memptr *q;
q = (memptr *) (((char *) memp) - ALIGNSIZE);
size = q->size;
thanks
Chuck
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Number of bytes returned by malloc (or passed to free)?
1995-03-04 12:08 Number of bytes returned by malloc (or passed to free)? cek
@ 1995-03-05 16:12 ` Dan Pop
1995-03-06 23:21 ` cek
0 siblings, 1 reply; 4+ messages in thread
From: Dan Pop @ 1995-03-05 16:12 UTC (permalink / raw)
In <3j9l81$lo8@netaxs.com> cek@netaxs.com () writes:
>Does anyone know how to determine for OSF/1 on an alpha 3000 how many
>bytes are actually allocated by malloc? I know this type of code is
>non-portable and should not be relied upon but I only use it for
>testing. I use it as a simple check for memory leakage by checking
>the difference between the total bytes allocated by malloc and the
>total bytes released by free. I am using OSF/1 V1.3 but will soon be
>upgrading to OSF/1 V3.2
If free doesn't release all the bytes allocated by malloc, then it's
severely broken.
>
>If anyone is interested, here is the SUN Sparc (4.1.3) version of what
>I need:
>
Your code doesn't show how to check that free releases to the heap all
the bytes allocated by malloc.
Dan
--
Dan Pop
CERN, CN Division
Email: danpop@cernapo.cern.ch
Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Number of bytes returned by malloc (or passed to free)?
1995-03-05 16:12 ` Dan Pop
@ 1995-03-06 23:21 ` cek
1995-03-15 18:57 ` Eric Osborne
0 siblings, 1 reply; 4+ messages in thread
From: cek @ 1995-03-06 23:21 UTC (permalink / raw)
Dan Pop (danpop@cernapo.cern.ch) wrote:
: In <3j9l81$lo8@netaxs.com> cek@netaxs.com () writes:
: >Does anyone know how to determine for OSF/1 on an alpha 3000 how many
: >bytes are actually allocated by malloc? I know this type of code is
: >non-portable and should not be relied upon but I only use it for
: >testing. I use it as a simple check for memory leakage by checking
: >the difference between the total bytes allocated by malloc and the
: >total bytes released by free. I am using OSF/1 V1.3 but will soon be
: >upgrading to OSF/1 V3.2
: If free doesn't release all the bytes allocated by malloc, then it's
: severely broken.
: >
: >If anyone is interested, here is the SUN Sparc (4.1.3) version of what
: >I need:
: >
: Your code doesn't show how to check that free releases to the heap all
: the bytes allocated by malloc.
: Dan
Dan,
My original request must have been unclear. I want to check my application's
USE of malloc and free -- not the functions malloc and free themselves.
I create two fns. my_malloc and my_free. The application makes calls to
my_malloc and my_free instead of calling malloc and free directly.
my_malloc passes the memory request to malloc and then determines how
many bytes were actually allocated by malloc (a number >= the number of
bytes actually requested). This number is then added to
global_number_of_bytes_allocated. my_free works in a similar manner --
it determines how many bytes are being freed and then adds that number
to global_number_of_bytes_freed. When the program is ready to exit,
if (global_number_of_bytes_allocated - global_number_of_bytes_freed) > 0,
then the application has a memory leak.
I am looking for the OS specific code for determining the size of a
block of memory given a pointer to the block.
thanks
Chuck
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Number of bytes returned by malloc (or passed to free)?
1995-03-06 23:21 ` cek
@ 1995-03-15 18:57 ` Eric Osborne
0 siblings, 0 replies; 4+ messages in thread
From: Eric Osborne @ 1995-03-15 18:57 UTC (permalink / raw)
cdk@netaxs.com writes :
>if (global_number_of_bytes_allocated - global_number_of_bytes_freed) > 0,
>then the application has a memory leak.
You might want to check out the "3rd degree" tool that is available on
DEC OSF/1, I think as part of the developer extension - it's one of the
ATOM tools. It does a marvelous job of finding memory leaks, and will also
detect things like references to unitialized variables. I used it a lot
a while back, and was able to detect a number of heap corruption problems
in a large piece of networking code. Interestingly enough, these same
problems were NOT detected by Purify from Pure Software. That's not an
add, nor a slam on Purify - just my personal experience.
Eric Osborne
*****************************************************************************
Note - the opinions expressed above are my own, and do not necessarily
represent those of the Ohio State University. For a small fee, they may
become your opinions as well.
*****************************************************************************
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1995-03-15 18:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-03-04 12:08 Number of bytes returned by malloc (or passed to free)? cek
1995-03-05 16:12 ` Dan Pop
1995-03-06 23:21 ` cek
1995-03-15 18:57 ` Eric Osborne
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox