www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/13/06:35:20

Message-ID: <32105403.267E@pobox.oleane.com>
Date: Tue, 13 Aug 1996 12:08:03 +0200
From: Francois Charton <deef AT pobox DOT oleane DOT com>
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: <Pine DOT SUN DOT 3 DOT 91 DOT 960813085846 DOT 28748M-100000 AT is>

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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019