TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Ali Cinar
from: Pascal Schmidt
date: 2003-10-18 16:58:16
subject: Memory matters

Hi Ali! :-)

 AC> If you are using GNU's C compiler, it comes with a function
 AC> named alloca() (declared in alloca.h) . When you use alloca()
 AC> instead of malloc() in a function, then the compiler automaticaly
 AC> free the memory for you when the function exits/returns.
 AC> It is very useful when dealing with big functions.
alloca() is defined in the C standard, it's not a compiler feature. Be
aware that alloca() allocates memory on the stack, and that may be limited
in size on some operating systems.

Note that no freeing actually takes place because the stack pointer is
simply reset to its old value when the function exits, anyway. ;) That also
means one needs to be careful not to store a pointer returned from alloca()
in some other place that could be accessed after the function has returned.
If such a pointer were accessed later, it could smash the stack.

Ciao
Pascal

--- Msged/LNX 6.1.1
* Origin: What about their legs? They don't need those. (1:153/401.2)
SEEN-BY: 633/267 270
@PATH: 153/401 307 140/1 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™.