472,145 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 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 4527
<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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by subirs | last post: by
64 posts views Thread by Robert Seacord | last post: by
reply views Thread by leo001 | last post: by

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.