TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: JOHN GARDENIERS
from: DARIN MCBRIDE
date: 1998-01-18 20:03:00
subject: Free(question)

 JG> Up till now, whenever I've needed memory for working 
 JG> with a large number of
 JG> strings I malloc()ed the whole lot in one go. I've seen 
 JG> a number of examples
 JG> posted here which malloc() just enough memory for one 
 JG> string at a time. This
 JG> obviously has both advantages and disadvantages. The 
 JG> one thing I haven't seen
 JG> is an example of how such a dynamically allocated array 
 JG> is free()ed. Must I
 JG> have a matching free() for each malloc() or can it all 
 JG> be free()ed at once?
I'm not entirely sure what your question is, but the answer is that there 
must be a matching free for every malloc/calloc/strdup, and a matching delete 
for every new (C++ only)(*).
(*) Preparing for any possible merger of C_ECHO/C_PLUSPLUS.  :-)
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

SOURCE: echomail via exec-pc

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