Regarding free function

V

Vijay

Hi All,

I have one question.

Using free we can release the memory. After releasing memory where this
released memory will go.. Does it go to back operating system or not?
Please explain.


Regards,
Vijay
 
R

Richard Heathfield

Vijay said:
Hi All,

I have one question.

Using free we can release the memory. After releasing memory where this
released memory will go.. Does it go to back operating system or not?

The Standard says: "The free function causes the space pointed to by ptr to
be deallocated, that is, made available for further allocation."

Some people interpret this as meaning that the implementation must hang on
to the memory in case the program wants it back again... and others don't.
 
F

Flash Gordon

Vijay said:
Hi All,

I have one question.

Using free we can release the memory. After releasing memory where this
released memory will go.. Does it go to back operating system or not?
Please explain.

On the HS 7000 it goes on a skiing holiday. However, other systems are
likely to behave differently. It is not required to be returned to the
OS and on many systems it won't be, instead it will be held in some kind
of pool of memory easily available for use in subsequent calls to
malloc/realloc. If you want to know about your system, ask in a group
dedicated to your system.
 
V

Vijay

Flash said:
On the HS 7000 it goes on a skiing holiday. However, other systems are
likely to behave differently. It is not required to be returned to the
OS and on many systems it won't be, instead it will be held in some kind
of pool of memory easily available for use in subsequent calls to
malloc/realloc. If you want to know about your system, ask in a group
dedicated to your system.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

ok. Is there any way to return released memory back to OS explicitly?
Regards,
Vijay
 
C

CBFalconer

Richard said:
Vijay said:


Call the exit() function, or return from main().

<quibble> On some systems, and if the main from which you return is
the outer level main, i.e. not a recursive call. The DS9000
assigns malloced memory from a stock of fusible link PROMs. It
goes through some gyrations to write that memory more than once.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
F

Flash Gordon

Richard said:
Vijay said:


Call the exit() function, or return from main().

That is return from the original call to main, remember it can be called
recursively ;-)

Calling abort should work as well.

If the OP wants to release memory back to the OS without exiting the
program, then he will have to go to a group dedicated to his system.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
 
R

Richard Heathfield

Flash Gordon said:
That is return from the original call to main, remember it can be called
recursively ;-)

Yes, I know - I thought of recursive main() /just/ after posting. 'Twas ever
thus, n'est-ce-pas?
Calling abort should work as well.

Yup. There are also numerous non-9899 methods (e.g. POSIX) for achieving the
same objective, but let's not go there.
 
F

Flash Gordon

Richard said:
Flash Gordon said:


Yes, I know - I thought of recursive main() /just/ after posting. 'Twas ever
thus, n'est-ce-pas?
Indeed.


Yup. There are also numerous non-9899 methods (e.g. POSIX) for achieving the
same objective, but let's not go there.

Yes, but those are off topic here :)
 
J

Jordan Abel

<quibble> On some systems, and if the main from which you return is
the outer level main, i.e. not a recursive call. The DS9000
assigns malloced memory from a stock of fusible link PROMs. It
goes through some gyrations to write that memory more than once.

So how are pointers represented with %p on a DS9k?
 
E

Eric Sosman

Jordan said:
So how are pointers represented with %p on a DS9k?

Every pointer value has the printed representation

"You are in a twisty little maze of passages, all different."
 
J

Jordan Abel

Every pointer value has the printed representation

"You are in a twisty little maze of passages, all different."

And how am I supposed to translate those back to the original pointer?
 
R

Robert Gamble

Jordan said:
Then you don't have a conforming implementation.

I did not realize that the Standard made such a guarantee but as I am
reviewing the section detailing the fscanf function I see that it does.
I am slightly surprised.

Robert Gamble
 
F

Flash Gordon

Robert said:
I did not realize that the Standard made such a guarantee but as I am
reviewing the section detailing the fscanf function I see that it does.
I am slightly surprised.

However, Jordan is still not expected to translate it back. Only the
implementation is, and as long as it can manage it (for example keeping
a table of what textual representation it has use for what pointer) it
can use any representation it likes.
 
J

Jordan Abel

However, Jordan is still not expected to translate it back. Only the
implementation is, and as long as it can manage it (for example keeping
a table of what textual representation it has use for what pointer) it
can use any representation it likes.

But it can't use the exact same representation for two different pointers.

Note that I did not say it has to have any relationship to the
representation in memory - it can store the pointers in a table and
print an index into that table.

However, unless you subscribe to the "evil padding bits" theory, it
_also_ has to be legal to take the address of the pointer, cast to
pointer to unsigned char, and print sizeof(void*) bytes as a hex dump,
and then copy those bytes back.
 
F

Flash Gordon

Jordan said:
But it can't use the exact same representation for two different pointers.
True.

Note that I did not say it has to have any relationship to the
representation in memory - it can store the pointers in a table and
print an index into that table.

However, unless you subscribe to the "evil padding bits" theory, it
_also_ has to be legal to take the address of the pointer, cast to
pointer to unsigned char, and print sizeof(void*) bytes as a hex dump,
and then copy those bytes back.

What if the padding bits are only mischievous, not actually evil? ;-)

Actually, the standard does not define padding bits for a pointer, only
for integer types. So I believe that all bits in the pointer are part of
the representation and therefore unless you call free on that pointer
(which could make the representation become a trap) I believe using an
unsigned char pointer to save the representation to a file and later
reading it back and using it would be perfectly legal. However, remember
that different pointer types could be different sizes, so if you want to
use sizeof(void*) you should first assign the pointer to a void* variable.
 
E

Eric Sosman

Jordan said:
But it can't use the exact same representation for two different pointers.

It's difficult to reproduce DS9000 output on Usenet, which
may be why you seem to have overlooked the many font changes in
the fifty-nine characters of the printed representation. The
characters themselves are "carrier" rather than "signal," and
it's the font changes that encode the pointer value. This is
the same scheme Francis Bacon used to encode his secret messages
in the First Folio of the works of the so-called "Shakespeare."

;-)
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Eric said:
Every pointer value has the printed representation

"You are in a twisty little maze of passages, all different."

Eric, ISTR that the NULL pointer was treated differently.
Notwithstanding your comment about font changes as information and text
as carrier, on my old DS9000, the NULL pointer has a "%p" printed
representation of

"You are in a maze of twisty little passages, all alike."

;-)



- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEgCztagVFX4UWr64RAn1FAJ4+BHxzwHWalGy7SOci2aauU2UQQQCglWvq
cMwlqMH1o5yVWUldZiplS+I=
=HKRZ
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top