473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
58 4823
<vi******@gmail.comwrote in message
news:6e**********************************@a1g2000h sb.googlegroups.com...
On Aug 10, 2:21 pm, "Chris M. Thomasson" <n...@spam.invalidwrote:
<snip>
>FWIW, here is how I "attempt" to detect "smallest" maximum alignment;
welcome to hack world!:

http://groups.google.com/group/comp....7e0d0e97c5e1d9

That code doesn't work.

from that post:
> unsigned char* rawbuf[(SUPERBLOCK_SIZE * 2) - 1];

(Where SUPERBLOCKSIZE is 4096 * 8)
It exceeds environmental limits, thus all compilers can refuse to
compile it.
DOH! Yes. Okay, well, if you can "temporarily" overlook that retarded error
in the "example" application, I was wondering if you can give me any clever
suggestions on how to improve the alignment hack code itself: Basically, all
the code that exists above the following line:

#define L2CACHE_SIZE 128
BTW, thanks for taking the time to look at the hackish freak code and inform
me of the nasty error!

I really do appreciate it.

Aug 10 '08 #51
Ian Collins wrote:
CBFalconer wrote:
>Ian Collins wrote:
.... snip ...
>>And most, if not all, c99 compilers would inline the function
whether or not the "inline" keyword was present.

Oh? Is that legal?

Can you either cite a reference where it's disallowed or a reason
why it shouldn't be legal?
Rather hard to take a pointer to an inlined function.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Aug 10 '08 #52
"CBFalconer" <cb********@yahoo.comwrote in message
news:48***************@yahoo.com...
Ian Collins wrote:
>CBFalconer wrote:
>>Ian Collins wrote:
.... snip ...
And most, if not all, c99 compilers would inline the function
whether or not the "inline" keyword was present.

Oh? Is that legal?

Can you either cite a reference where it's disallowed or a reason
why it shouldn't be legal?

Rather hard to take a pointer to an inlined function.
I don't see this being impossible.

You simply keep your non-inlined version around, as well as all the inlined
versions.

--
Bartc

Aug 10 '08 #53
CBFalconer <cb********@yahoo.comwrites:
Ian Collins wrote:
>CBFalconer wrote:
>>Ian Collins wrote:
.... snip ...
And most, if not all, c99 compilers would inline the function
whether or not the "inline" keyword was present.

Oh? Is that legal?

Can you either cite a reference where it's disallowed or a reason
why it shouldn't be legal?

Rather hard to take a pointer to an inlined function.
Functions aren't inlined. Function calls are inlined. Inlining a
call doesn't prevent taking the address of the function (as long as a
non-inlined version of the function is kept).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 10 '08 #54
Keith Thompson wrote:
CBFalconer <cb********@yahoo.comwrites:
.... snip ...
>
>Rather hard to take a pointer to an inlined function.

Functions aren't inlined. Function calls are inlined. Inlining
a call doesn't prevent taking the address of the function (as
long as a non-inlined version of the function is kept).
That makes no sense to me. If you inline the following:

inline int sq(int a) {return a * a;}

you do not expect to waste any time assigning registers, creating a
stack marker, executing a call, etc. All you want to do is execute
that action in line.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
Aug 11 '08 #55
CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
... snip ...
>>
>>Rather hard to take a pointer to an inlined function.

Functions aren't inlined. Function calls are inlined. Inlining
a call doesn't prevent taking the address of the function (as
long as a non-inlined version of the function is kept).

That makes no sense to me. If you inline the following:

inline int sq(int a) {return a * a;}

you do not expect to waste any time assigning registers, creating a
stack marker, executing a call, etc. All you want to do is execute
that action in line.
Of course, that's the purpose of inlining. But it doesn't preclude
taking the function's address.

Let's ignore the "inline" keyword for the moment, and just consider
inlining as an optimization that might be performed by a pure C90
compiler. Given a function like the one you've defined:

int sq(int a) { return a * a; }

one *call* might be inlined:

int x = whatever;
int y = sq(x); /* sq(x) expanded to x * x */

while another call might be implemented as an ordinary function call.
So inlining is an attribute of a given function, call, not necessarily
of a function.

And it's still perfectly legal to take the address of the "sq"
function, and to use that address later in an indirect call. Such an
indirect call can't easily be inlined, which means that a function
body must be provided (unless the compiler can prove it's not
necessary).

The C99 inline specifier is an suggestion to the compiler to inline
calls to that function. Note that the standard doesn't forbid taking
the address of a function declared with the inline specifier. (If it
did, calls would be impossible, since a simple function call
implicitly takes the address of the function.)

If you declare (in C99):

inline int sq(int a) {return a * a;}

then you're suggesting that calls to sq should be as fast as possible
(see C99 6.7.4 for the exact wording), but you're *not* giving up the
possibility of computing and storing the address of sq.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 11 '08 #56
sh******@gmail.com wrote:
On Aug 8, 7:52 pm, Chris Dollin <chris.dol...@hp.comwrote:
sh.vi...@gmail.com wrote:
is there any way to find out number of bytes freed on a particular
free() call in C
Not portably.

Usually you don't need to know; free frees what malloc malloced.

What is it that you'd do with the answer, were you to have it?

--
'It changed the future .. and it changed us.' /Babylon 5/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
[ Please don't quote .sigs. ]
i am writing a simple application where i want to keep track of number
of bytes my process is using currently or peak memory used by my
process so far.
Why?

If it's to report to your users, don't. They don't care, until the
program crashes because it's ran out of memory, in which case _all_ of
your program is using "too much" memory, not one specific point of it.
Under normal circumstances, this is irrelevant, overly technical
information for normal users.

If it's for your own curiosity, or for debugging, consider using
something like ValGrind, or similar suites, which have been created
specifically to do this and lots more, and give you all the information
you could ever need.

Richard
Aug 11 '08 #57
"Bartc" <bc@freeuk.comwrote:
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
"the sky is blue" is not a portable assumption.

So what colour is 'sky blue'?
#87CEEB, of course...

Richard
Aug 11 '08 #58
On Sat, 09 Aug 2008 20:44:30 -0700, Keith Thompson <ks***@mib.org>
wrote:
CBFalconer <cb********@yahoo.comwrites:
How about:
"inline size_t get_parent_index(size_t idx) {return idx/2;}"

How about ``syntax error before "size_t"'' if your (pre-C99) compiler
doesn't recognize the "inline" keyword?

Yes, most pre-C99 compilers probably do support inline as an extension
(and of course any C99 compiler must support it), but just the other
day you told somebody that he *must* place all his declarations before
statements in a block.
You can usually C89ify (C99) 'inline's with -Dinline= or equivalent.
There is no such trivial fix for declaration-after-statement.
(You can introduce nested blocks, but then you're not actually using
declaration-after-statement after all.)

- formerly david.thompson1 || achar(64) || worldnet.att.net
Aug 25 '08 #59

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

Similar topics

2
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...
3
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....
22
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...
64
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...
4
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.