Re: stack questions
- From: "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT com>
- Date: Wed, 22 Oct 2008 09:22:47 -0700
My first question is: Can the stack be made bigger? I presume there is a
platform specific caveat to this since the documentation does not suggest
anything for making the stack bigger.
Why? Unless you are overflowing the stack, don't waste your time worrying
about how much address space is set aside for it.
My second question has to do with the use of malloc. The multiple threads
of my application use a Semaphore and WaitForSingleEvent on that semaphore
to
prevent multiple threads from executing simultaneously. This permits each
thread to then inspect and/or modify the malloced linked list. Does
malloc
allocate memory outside the stack space? The documentation refers to
using
the HEAP which I always understood to be the other end of the same stack
block of memory. This linked list can grow to be larger than 64k, the
default size of stack. Is what I'm doing safe or is this disaster in the
making?
I don't think that you want a semaphore, but a mutex, since you have a
single resource, not multiple resources, to protect.
Yes, malloc allocates memory on the heap, not the stack (this is exactly how
every compiler I can ever remember using has worked). No, the heap is
unrelated to the stack, other than the fact that the application can access
both. The heap will grow, if you make a memory request that can't be
satisfied with the current allocation, and this has NOTHING to do with the
stack size setting on the linker command line.
Paul T.
.
- Follow-Ups:
- Re: stack questions
- From: Boyd
- Re: stack questions
- References:
- stack questions
- From: Boyd
- stack questions
- Prev by Date: stack questions
- Next by Date: Re: stack questions
- Previous by thread: stack questions
- Next by thread: Re: stack questions
- Index(es):
Relevant Pages
|