Re: how much memory a pthread can define a variable in a stack?

From: David Schwartz (davids_at_webmaster.com)
Date: 11/21/03

  • Next message: RSmith6559: "Re: error only when run from cronjob"
    Date: Fri, 21 Nov 2003 14:41:46 -0800
    
    

    "Jaguk Ku" <jkku@kynax.com> wrote in message
    news:bpjrvi$7lo$1@news1.kornet.net...

    > I have an simple application which define a struct variable in a function
    > which size is about 3 Megabyte.
    > It works.

        This is very, *VERY* bad practice. What do you think the system should
    do if there's less than 3 megabytes available?

    > But when it is defined in a pthread program. it just died.

        It's not guaranteed to work under any circumstances.

    > My computer is Sun E450, Solaris 8, memory is 1024 Mega, swap 3 Giga.
    >
    > What should i do?

        Use 'malloc' or 'new' or some appropriate memory allocation mechanism.
    In addition, get in the habit of scanning your code regularly for excessive
    stack consumers.

    > Do i have to allocate a struct variable in a heap? or is there any runtime
    > option for a thread to get more stack memory?

        There is, but that's not a very good solution. Generally, the option
    just reserves the address space, and you leave the system with no way to
    tell you later that the memory isn't available.

    > what is the maximum amout of memory to define a variable in a stack
    usually?

        It depends upon the function's intended use. It's okay to use more stack
    in a function that's not going to be deep in a function call stack. I
    recommend 8Kb maximum for a library function and 32Kb as an absolute
    maximum.

        DS


  • Next message: RSmith6559: "Re: error only when run from cronjob"

    Relevant Pages

    • Re: When is "volatile" used instead of "lock" ?
      ... If I pass it a reference to stack memory, ... *hugely* unsafe to let another thread start arbitrarily writing to ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: doubts in multi threaded application (win32 console + mfc)
      ... Thank you all (Scott McPhillips,Carl Daniel,Alex and aao) for your prompt ... What is maximum size for stack memory in multi threaded ... It highly depends on the usage and lifetime of an object, ...
      (microsoft.public.vc.language)
    • Re: Array scope
      ... `auto' variables are allocated on a stack, ... implementations feel free to modify the stack memory ... addressed by your bogus pointer. ...
      (comp.lang.c)
    • Re: doubts in multi threaded application (win32 console + mfc)
      ... I am creating objects in stack memory. ... In which memory (Stack or Heap) I have to create objects to improve the performance? ... CString performance will probably improve if you upgrade to VC++ 2005. ...
      (microsoft.public.vc.language)
    • Re: Firewire ethernet on FC8
      ... seems noone has conquered this. ... I have not yet finished porting eth1394 to the new stack. ... For now I'd recommend a pair of cheap ethernet cards and a crossover ...
      (Fedora)