Re: how much memory a pthread can define a variable in a stack?
From: David Schwartz (davids_at_webmaster.com)
Date: 11/21/03
- Previous message: Mark Rafn: "Re: Time to live on messages"
- In reply to: Jaguk Ku: "how much memory a pthread can define a variable in a stack?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Mark Rafn: "Re: Time to live on messages"
- In reply to: Jaguk Ku: "how much memory a pthread can define a variable in a stack?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|