From owner-freebsd-hackers Fri Jul 12 9: 1:17 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1BC4237B400 for ; Fri, 12 Jul 2002 09:01:14 -0700 (PDT) Received: from mail8.nc.rr.com (fe8.southeast.rr.com [24.93.67.55]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5B97343E42 for ; Fri, 12 Jul 2002 09:01:13 -0700 (PDT) (envelope-from bts@babbleon.org) Received: from i8k.babbleon.org ([66.57.86.84]) by mail8.nc.rr.com with Microsoft SMTPSVC(5.5.1877.757.75); Fri, 12 Jul 2002 11:59:55 -0400 Received: by i8k.babbleon.org (Postfix, from userid 111) id B4F0BBA05; Fri, 12 Jul 2002 11:59:51 -0400 (EDT) Content-Type: text/plain; charset="iso-8859-1" From: Brian T.Schellenberger To: Yar Tikhiy , hackers@FreeBSD.ORG Subject: Re: Large variables on stack Date: Fri, 12 Jul 2002 11:59:51 -0400 X-Mailer: KMail [version 1.3] References: <20020712194809.A62768@comp.chem.msu.su> In-Reply-To: <20020712194809.A62768@comp.chem.msu.su> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <20020712155951.B4F0BBA05@i8k.babbleon.org> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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