[uClibc] Stack vs. Heap allocation

Clark Williams williams at redhat.com
Wed Jul 13 16:15:29 UTC 2005


On Tue, 2005-07-12 at 18:19 -0400, Garrett Kajmowicz wrote:
> In the uClibc++ library, there are a number of places where I am currently 
> using heap allocation for buffers (default size is 32 characters).  At what 
> point in an embedded system is it safe to use stack allocation instead?  I'd 
> be able to elliminate the need for a pointer variable, cut out the calls to 
> malloc/free and all of the internal maintainance which goes along with that.  
> However, I'm not certain how well embedded systems handle growth on the 
> stack, either.
> 

I was going to jump up and down and shout "Never use the stack!", but I
calmed down and thought about it a bit :).

I think that it would depend on whether you're running on uClinux or
Linux. On a machine with an MMU, you run out of stack, the os just goes
and gets another page and keeps going (at least until you collide with
the .text address region or run out of memory :). Not so on a uClinux
box where you're pretty much stuck with the address region your process
got.

I still think that if you're trying to address both cases with one set
of code, you're safer using the heap. Just my opinion though...

Clark

-- 
Clark Williams <williams at redhat.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20050713/c4aee33f/attachment-0002.pgp 


More information about the uClibc mailing list