Message-ID: <32105403.267E@pobox.oleane.com> Date: Tue, 13 Aug 1996 12:08:03 +0200 From: Francois Charton Organization: CCMSA MIME-Version: 1.0 To: djgpp AT delorie DOT com CC: eliz AT is DOT elta DOT co DOT il Subject: Re: Freeing and not freeing Windoze memory References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii wrote: > But I don't recommend using it for allocations larger than, say 5KB. > That is because your function might be called in a deeply nested program, > when some (most) of the stack is already used up. Think about `alloca' > as a way to declare a variable-size local array: usually, when the array > size gets large, you'd prefer using `malloc' or declare it as a static. > The same logic applies to `alloca' IMHO. Agree : avoid alloca() if your program has pronounced recursive functions... and ban it for large data chunks. The main interest of alloca() is its speed, and the fact you do not need to bother about freeing. However, its is a bit less safe than malloc(). There are many programs, which stack never is much nested (no recursive functions), but which allocate many small chunks of memory. In this case alloca() can be a good alternative, and end up in significant speed improvements. BTW, do you think it would be possible for a compiler to optimise the use of memory (i.e. allocate in the stack whenever it is safe and possible, and in the heap in other time). Comments anyone ? Francois