Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Jul 2002 10:44:13 -0700 (PDT)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        "Mike Mitchell" <mmitchel@qualcomm.com>
Cc:        "Yar Tikhiy" <yar@comp.chem.msu.su>, <hackers@FreeBSD.ORG>
Subject:   Re: RE: Large variables on stack
Message-ID:  <200207121744.g6CHiDAi057989@apollo.backplane.com>
References:   <KAEBJMEAAINDJMODOPALCELDCPAA.mmitchel@qualcomm.com>

next in thread | previous in thread | raw e-mail | index | archive | help
    I think it's slightly more complex then that.  Sure, all modern
    UNIX systems can handle huge stack-based structures, but porting
    to other architectures is not the only concern one should have.

    Porting from a non-threaded to a threaded environment, for example,
    is a major concern.  Even in UNIX threaded environments typically
    only give 64K stacks to each thread.  In fact, we ran into this
    problem with our dynamic ELF loader library in both -stable and
    -current.  The loader was allocating a large symbol cache on the stack
    and when used in a threaded environment by large applications like
    OpenOffice it overflowed the thread stack.

    So as a rule of thumb what Yar learned is absolutely correct... all
    else being equal it is better to malloc() or statically declare 'large'
    structures rather then place them on the stack.  It should be noted that
    modern malloc()'s are very fast (and our's is especially good), 
    programmers should not be afraid of using it to allocate large temporary
    data structures.

    My definition of 'Large' in this context is that anything eating over a
    kilobyte should be reviewed.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>


:Good Morning,
:
:I would suggest that since we have an VM implementation that works,
:that the answer to your question is "it doesn't really matter." Now,
:the information you received about making these items static or
:heap allocated can be really beneficial when you are coding for
:an embedded system and you have very finite resources that you
:need to manually manage.
:
:Mike Mitchell
:
:-----Original Message-----
:From: owner-freebsd-hackers@freebsd.org
:[mailto:owner-freebsd-hackers@freebsd.org]On Behalf Of Yar Tikhiy
:Sent: Friday, July 12, 2002 8:48 AM
:To: hackers@freebsd.org
:Subject: Large variables on stack
:
:
: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?
:
:-- 
:Yar

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?200207121744.g6CHiDAi057989>