| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Memory matters |
On: 18 Oct 03 23:54:32 Bo Simonsen wrote to Roger Scudder: > So you set it to NULL after freeing it? > RS> #include "sniptype.h" /* for macro FREE(x) */ This is a simple mechanism that can be employed as part of a robust memory allocation scheme. The C standard specifies that if free() is passed a pointer with a value of NULL the pointer is to be ignored. (So like to test in their code, but AFAIK that is not necessary When a program contains a large number of pointers and dynamic allocation is used frequently it is very important to know at all times exactly where those pointers are pointing. The idea is to always set pointers equal to NULL when they are defined and after the block they point to has been free'd. > #define FREE(x) free(x); x = NULL; > or? Yes, that will work as well. One thing though... when writing a macro, always surround the operands with parens. #define FREE(x) free(x); (x)=NULL; I find the version in snippets more elligant (I had originally written one like yours) because it works as one statement instead of two. It is a minor difference, so don't sweat it if you want to use your version. -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™.