TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Pascal Schmidt
from: Roger Scudder
date: 2003-10-18 11:22:44
subject: Memory matters

On: 17 Oct 03  16:54:50 Pascal Schmidt wrote to Roger Scudder:

 >  RS> Freeing a structure should be nothing more than one line...
 >  RS> free(PointerToMyStructure);

 > Unless the structure contains malloc'd pointers itself, in which case
 > those have to be freed first. Additional fun if the structures pointed to 
 > by embedded pointers can contain further pointers... :)

 Right... I was trying to get him to reveal the exact nature of his data.  

 > I usually code functions called destroy_foo() for each structure foo that 
 > has embedded pointers. That hides the complexety and code needing to 
 > destroy a variable temp of type foo does indeed only have to do
 >     destroy_foo(temp);

 That is a great way to handle deallocation that would otherwise be rather
messy.  By carefully partitioning functions and data in separate
translation units you can handle just about any scope and lifetime issues
tastefully.  

-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™.