On Tue, 2007-05-22 at 14:15 -0600, Michael L Torrie wrote:
> May I ask why you need to allocate this on the heap?  If all you need is
> the ability to be dynamic, and you know your array won't exceed the
> stack size, you can use gcc's alloca() allocator to allocate stack
> memory dynamically.  I use alloca extensively when dealing with string
> operations, for example.  You don't ever have to free the memory; just
> return from the subroutine and it's all cleared off.  You obviously
> cannot return a string as a return value from a parameter that's been
> alloca'ted.

Although I won't argue that putting the data on the stack might be
smarter, I will warn you that you should make your dependence on a small
data size explicit. Perhaps by including an assert() or similar at the
start of the function.

You haven't lived until you've debugged someone else's accidental stack
smasher with production down at 4am.

-- 
Stuart Jansen              e-mail/jabber: [EMAIL PROTECTED]
                           google talk:   [EMAIL PROTECTED]

"However beautiful the strategy, you should occasionally look at 
the results." -- Winston Churchill

Attachment: signature.asc
Description: This is a digitally signed message part

--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to