delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/22/22:25:47

From: alainm AT news DOT RISQ DOT QC DOT CA (Alain Magloire)
Subject: Re: freeing memory and exiting (safely)
Newsgroups: comp.os.msdos.djgpp
References: <83ril4$4ua$1 AT portraits DOT wsisiz DOT edu DOT pl>
X-Newsreader: TIN [version 1.2 PL2]
Lines: 36
Message-ID: <rCe84.372$36.7194@carnaval.risq.qc.ca>
Date: Thu, 23 Dec 1999 01:08:39 GMT
NNTP-Posting-Host: 132.206.63.174
X-Complaints-To: abuse AT mcgill DOT ca
X-Trace: carnaval.risq.qc.ca 945911319 132.206.63.174 (Wed, 22 Dec 1999 20:08:39 EST)
NNTP-Posting-Date: Wed, 22 Dec 1999 20:08:39 EST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Chaos (chengin AT alpha DOT net DOT pl) wrote:
: Hi there.

: In my program, I use several buffers which are dynamically allocated
: (malloc) and also freed during run time (free). For every buffer I'm setting
: condition which looks close to this:

: background=malloc(BACKGROUND_BUF_SIZE);
: if(!background)
:    {
:     fprintf(stderr,"Can't allocate memory for buffor ''background''! \n");
:     return 1;
:    }

: My question is that if the prog reaches that "return 1" (synonim for error)
: does those buffers will be safely deallocated?
: Generaly I'm interested about knowing is there any function that frees all
: previously allocated memory without asking me what buffer exist or not. I
: just want to exit safe from the program and deallocate it's memory without
: blocking it in later use.
: I know I want something very weird ;-)


No. C or the std C library does not provide such facilities.
When malloc()/realloc()/calloc() returns an error (NULL), it means
there is not space left to allocate, you could free() some
unused previously allocated buffers, do something else that does
not need to allocate memory or exit();

If you reach that level, it's maybe time for you to rethink,
your design and thight things up.

--
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019