Date: Fri, 12 Jul 2002 11:59:51 -0400 From: Brian T.Schellenberger <bts@babbleon.org> To: Yar Tikhiy <yar@comp.chem.msu.su>, hackers@FreeBSD.ORG Subject: Re: Large variables on stack Message-ID: <20020712155951.B4F0BBA05@i8k.babbleon.org> In-Reply-To: <20020712194809.A62768@comp.chem.msu.su> References: <20020712194809.A62768@comp.chem.msu.su>
next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 12 July 2002 11:48 am, Yar Tikhiy wrote:
| Hi there,
|
| As I see, there are many spots in the FreeBSD userland sources where
| multi-kilobyte automatic variables (e.g., string buffers) are used.
| I've been taught that such variables would better be static or
| allocated on heap.
|
| So the following question comes to my mind: To stay portable to a
| reasonable degree, how large on-stack variables can be used?
I believe that most advice of this nature dates back to the time when memory
was non-virtual. I suppose that I wouldn't allocate more than about 10k on
the stack, or less in a highly recursive application, but honestly I doubt
it's any big deal with 32-bit processors either way.
Besides, stack allocations are more efficient than heap allocations on every
architecture I know of other than the IBM mainframe.
Of course, it's is a lot better to dynamically allocate strings of unknown
length than to use large stack buffers, but that's because the dynamic
allocation can be done after you know the length of the string and can avoid
overflows more than because you don't want large stack allocations. In a
language like ForTran that allows variable-length automatically-allocated
function-scoped items I'd do even those off of the stack.
(Of course in ForTran you have no choice, but you know what I mean.)
--
Brian, the man from Babble-On . . . . bts@babbleon.org (personal)
http://www.babbleon.org
http://www.eff.org http://www.programming-freedom.org
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020712155951.B4F0BBA05>
