TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Bo Simonsen
from: Roger Scudder
date: 2003-10-17 06:49:26
subject: Memory matters

On: 16 Oct 03  15:47:29 Bo Simonsen wrote to Jasen Betts:

 >  JB> it's a good idea to free it at the end of the program, but most 
 >  JB> platforms will free it for you if you leave it allocated.

 > Indeed, just a big work to free a structure with mutch allocated memory, is 
 > there a easy way for free'ing such a thing?

Freeing a structure should be nothing more than one line...

free(PointerToMyStructure);

Since you say it will be "so much work"  I am thinking that you
may be doing something very complicated (perhapse messy).  Maybe you should
be rethinking how you allocate the memory in the first place.

 >  JB> one handy way to free global allocations is to put all the frees in 
 >  JB> an exitfunction and use atexit() to register it.

 > atexit is like a class destructer?

 No, it calls clean up functions that you register.  It's in the standard library.

 >  JB> another is not to allocate them but instead have them as ordinary 
 >  JB> global variables

 > ?

This is very basic stuff.  You should never have made it to malloc without
first  understanding variable scope and lifetime.

Oh well, I guess we all learn in our own way.  :-)

Read in your C book about external variables, static external and static
internal variables, and scope rules.

-Roger
--- Spinone v0.1.79 Win32
* Origin: Scudder's Point (1:261/38.11)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.