🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.msdos.programmer
5 messages
5 total messages Started by William White Tue, 05 Sep 1995 11:52
Freeing memory in #pragma exit
#7869
Author: William White
Date: Tue, 05 Sep 1995 11:52
13 lines
1179 bytes
	Is it better to free all allocated memory from new & malloc()...  by freeing 
it with a #pragma exit function, or a regular function just before exit() is 
called?  Using the #pragma exit way, I've been getting some lockup in my 
program... :(

        ---Will
+----------------------------------------------------------------------+
|     William White ®¯ Yakima, WA. ®¯ Hi-Country Foods Corporation     |
|    Quality Assurance Lab Technician ®¯ Computer Analyst/Programmer   | 
|             ** We make it, you drink it, you love it **              |
|Check out our new web page at http://www.wolfe.net/~hcfoods/index.html|
|       For my Public PGP key, please finger me at wcw@wolfe.net       |
+----------------------------------------------------------------------+
Re: Freeing memory in #pragma exit
#7871
Author: kim sang woo
Date: Wed, 06 Sep 1995 06:24
20 lines
1581 bytes
William White (wcw@wolfe.net) wrote:
: 	Is it better to free all allocated memory from new & malloc()...  by freeing 
: it with a #pragma exit function, or a regular function just before exit() is 
: called?  Using the #pragma exit way, I've been getting some lockup in my 
: program... :(

   Stay away from pragma exit...   You are better off using atexit()
functions.  it's supported by ANSI.
   You are missing the poiont of dynamic allocation if you were to
allocate memory and never release it until program ends.  You are better
of using hard coded array.

:         ---Will
: +----------------------------------------------------------------------+
: |     William White ®¯ Yakima, WA. ®¯ Hi-Country Foods Corporation     |
: |    Quality Assurance Lab Technician ®¯ Computer Analyst/Programmer   | 
: |             ** We make it, you drink it, you love it **              |
: |Check out our new web page at http://www.wolfe.net/~hcfoods/index.html|
: |       For my Public PGP key, please finger me at wcw@wolfe.net       |
: +----------------------------------------------------------------------+
Re: Freeing memory in #pragma exit
#7873
Author: The Amorphous Mass
Date: Wed, 06 Sep 1995 21:28
21 lines
1543 bytes
On 5 Sep 1995, William White wrote:

> 	Is it better to free all allocated memory from new & malloc()...  by freeing 
> it with a #pragma exit function, or a regular function just before exit() is 
> called?  Using the #pragma exit way, I've been getting some lockup in my 
> program... :(

#pragma exit (or #pragma _anything_) is non-portable.

  When you're programming in C, deallocate all malloc()'d memory with 
the "regular" Standard Library function free().
  In C++, use the "regular" keyword delete to destroy all objects you 
allocate with new.

  *Never* mix new and malloc(), or delete and free(), in the same 
program.  They are *not* guaranteed to cooperate, and since they belong 
to two different languages there's no reason that they should.

___________
Bushido, n.: the ancient art of keeping your  | James Robinson
cool when a US President ralphs in your lap.  | james-f-robinson@uiowa.edu
Re: Freeing memory in #pragma exit
#7874
Author: Derick J.R. Qua-Gonzalez
Date: Thu, 07 Sep 1995 07:32
24 lines
1434 bytes
wcw@wolfe.net (William White) writes:

>	Is it better to free all allocated memory from new &
>malloc()...  by freeing it with a #pragma exit function, or a regular
>function just before exit() is called?  Using the #pragma exit way,
>I've been getting some lockup in my program... :(


The #pragma is inherently non-portable. The OS should free all of the
memory you malloc'd or new'd, although it is wise to be more careful
with memory management if the program is to have long termporal
existence.

// DQG.


--
+------------------------------------------------------------------------+
| Derick R. Qua-Gonzalez                                      | ________ |
| Department of High Energy Physics, Cal State University     | \      / |
| dqua@dqua.EarthLink.Net                                     |  \    /  |
|     ``It is better to be hated for what one is,             |   \  /   |
|       than loved for what one is not.'' (A. Gide)           | G  \/ USA|
+-------------------------------------------------------------+----------+
Re: Freeing memory in #pragma exit
#7875
Author: Guest
Date: Thu, 07 Sep 1995 17:58
11 lines
951 bytes
In article <42hdl3$rkr@ratty.wolfe.net>, William White <wcw@wolfe.net> wrote:
>	Is it better to free all allocated memory from new & malloc()...  by freeing 
>it with a #pragma exit function, or a regular function just before exit() is 
>called?  Using the #pragma exit way, I've been getting some lockup in my 
>program... :(

Don't call library functions in any #pragma exit registered functions.

As to freeing the memory, if you're program ends already there is really
no need to start freeing memory shortly before that.  Simply exiting the
program will free the memory afterward.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads