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 . . . . [EMAIL PROTECTED] (personal) http://www.babbleon.org http://www.eff.org http://www.programming-freedom.org To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message