473,561 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to find number of bytes freed

is there any way to find out number of bytes freed on a particular
free() call in C
Aug 8 '08 #1
58 4869
sh******@gmail. com said:
is there any way to find out number of bytes freed on a particular
free() call in C
When you allocate this storage, you know how much storage you allocated.

Don't Forget.

Then, when you come to free it, you know, right?

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 8 '08 #2
On Aug 8, 9:58*am, sh.vi...@gmail. com wrote:
is there any way to find out number of bytes freed on a particular
free() call in C
The only portable way is to store that information when you initially
allocate the memory (and update it if you subsequently successfully
call realloc using that pointer). If you want non-portable ways, you
could try asking in a platform specific group. Even there, it may
depend on what specific standard library implementation you are using,
and may simply not be available by any means.

-David
Aug 8 '08 #3
On Aug 8, 7:10 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
sh.vi...@gmail. com said:
is there any way to find out number of bytes freed on a particular
free() call in C

When you allocate this storage, you know how much storage you allocated.

Don't Forget.

Then, when you come to free it, you know, right?

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
yea but then i will have to store this information (number of bytes
allocated) at the time of allocation. so also a link between a pointer
and number of bytes it is linked with ...esentially i don;t want to
write my own memory allocator.
Aug 8 '08 #4
On Aug 8, 5:12 pm, sh.vi...@gmail. com wrote:
On Aug 8, 7:10 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
sh.vi...@gmail. com said:
is there any way to find out number of bytes freed on a particular
free() call in C
When you allocate this storage, you know how much storage you allocated.
Don't Forget.
Then, when you come to free it, you know, right?
--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

yea but then i will have to store this information (number of bytes
allocated) at the time of allocation. so also a link between a pointer
and number of bytes it is linked with ...esentially i don;t want to
write my own memory allocator.

Don't quote sig blocks.
see rfc 2646 4.3
If you don't want to do something, then don't. Simple, isn't it?
Aug 8 '08 #5
On Aug 8, 7:06 pm, David Resnick <lndresn...@gma il.comwrote:
On Aug 8, 9:58 am, sh.vi...@gmail. com wrote:
is there any way to find out number of bytes freed on a particular
free() call in C

The only portable way is to store that information when you initially
allocate the memory (and update it if you subsequently successfully
call realloc using that pointer). If you want non-portable ways, you
could try asking in a platform specific group. Even there, it may
depend on what specific standard library implementation you are using,
and may simply not be available by any means.

-David
ok . agreed. i hoped there might be some standard way in which guard
bytes store the information about the allocated memory. if it is
library specific there might not be any way for this. because then
libararies even might not even allocate gurad byte alongwith the data.
Aug 8 '08 #6
sh******@gmail. com wrote:
On Aug 8, 7:10 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
>sh.vi...@gmail .com said:
is there any way to find out number of bytes freed on a particular
free() call in C

When you allocate this storage, you know how much storage you
allocated.

Don't Forget.
yea but then i will have to store this information (number of bytes
allocated) at the time of allocation. so also a link between a pointer
and number of bytes it is linked with ...esentially i don;t want to
write my own memory allocator.
This is not possible in Standard C. But many implementations of C do
provide extensions for this rather commonly felt need. You should ask
in a group for your implementation, or better yet, just read the
documentation for your system's C library.

Aug 8 '08 #7
sh******@gmail. com said:
On Aug 8, 7:10 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
>sh.vi...@gmail .com said:
is there any way to find out number of bytes freed on a particular
free() call in C

When you allocate this storage, you know how much storage you allocated.

Don't Forget.

Then, when you come to free it, you know, right?
yea but then i will have to store this information (number of bytes
allocated) at the time of allocation.
Right. You can't have something for nothing. If you want to remember, it
will take up some memory.
so also a link between a pointer
and number of bytes it is linked with ...esentially i don;t want to
write my own memory allocator.
Then don't!

Why do you care how many bytes are freed? (No, I know it's none of my
business, but it may well be that there is a simple solution to your
underlying problem.)

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 8 '08 #8
In article <ic************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>sh******@gmail .com said:
>is there any way to find out number of bytes freed on a particular
free() call in C
>When you allocate this storage, you know how much storage you allocated.
>Don't Forget.
>Then, when you come to free it, you know, right?
The number of bytes of the allocation request is not necessarily
the same as the number of bytes freed.

When one makes an allocation request, one might be given a pointer into
the middle of of chunk of memory, with the initial part used as
overhead by the memory allocator; for example in some memory
allocators, it might be used to contain the size of the object.

Or the allocator might choose to allocate in quantums of a particular
size, or the allocator might use a binary page-splitting algorithm,
so the size of the object actually allocated and pointed to might
be larger than the size requested.

When the free() call is made, all of these overhead bytes and
extra bytes are freed -- so the number of bytes freed does not
necessarily match the number of bytes allocated.
--
"Whenever there is a hard job to be done I assign it to a lazy
man; he is sure to find an easy way of doing it."
-- Walter Chrysler
Aug 8 '08 #9
In article <g7*********@ca nopus.cc.umanit oba.ca>,
Walter Roberson <ro******@ibd.n rc-cnrc.gc.cawrote :
>When the free() call is made, all of these overhead bytes and
extra bytes are freed -- so the number of bytes freed does not
necessarily match the number of bytes allocated.
Opps, I meant "so the number of bytes freed does not necessarily
match the number of bytes requested for allocation."
--
"Allegories are in the realm of thoughts, what ruins are in
the realm of things." -- Walter Benjamin
Aug 8 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2064
by: Vince | last post by:
I have a very specific problem to solve but I cannot find a data structure for it. I don't know if I am posting on the good newsgroup but I cannot find a software.design group. I would like to declare a smart structure initialized via a XML file. The goal of this structure is to store data from a smart card. My XML file describes the file...
3
2222
by: subirs | last post by:
Hi, I am using mtrace to check for memory leaks in my code. The code is divided into many fucntion which are placed in different directories. While using mtrace the following output is given. Now the problem is to find where in the code and in which function memory leaks occurs as the trace does not give line number or name of the ...
22
3996
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to receive 5 bytes buffer , I call the BeginReceive and then wait on AsyncWaitHandle.WaitOne() but it is signald imidiatly , and the next call to...
64
8310
by: Robert Seacord | last post by:
The C standard doesn't say anything about what happens when you call realloc with a size argument of 0. Both glibc and openbsd appear to return a valid pointer to a zero-sized object.. e.g. the return of a malloc(0). Does anyone know of a runtime where realloc() free'ed the object and then returned NULL? If so, it would make the following...
4
2378
by: joyce | last post by:
hi How would I go abouts finding out how many bytes a string has. ( I want to do this so that I can set the datatype on the database approriately.) Thanks Joyce
5
3816
by: Prabhakar Rao | last post by:
For ex if memory allocated like below p = malloc(100) . . . . . free(p) how the free routine know, how much memory to be freed?
0
7647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7859
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7618
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5472
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5187
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3600
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1181
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.