Re: stack questions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.


.



Relevant Pages

  • Re: prefast "stack hog" warning for newed array
    ... Consider moving some data to heap. ... > Does not new allocate memory from the heap? ... > the stack then wouldn't a new'd object be lost when the function ... new allocates from the heap and this warning is bogus. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: How does managed code work?
    ... Does it work the same way as the native stack with a frame pointer that is the head of a linked list of stack frames where each time we enter a function we create a new stack frame in which new variables are pushed and each time we exit a function the entire stack frame is popped? ... Can someone point me to a discussion of the managed heap? ... How does it prevent memory leaks that occur in COM when two objects reference each other and keep the others reference count nonzero? ... Because objects don't go out of scope, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Groovy (war Re: [PROST]Re: CDC Plugin fuer Eclipse)
    ... Warum müsste man continuations erlauben Stackvariablen in den Heap zu verschieben? ... Ein activation record speichert die Parameter und lokalen Variablen der Funktion und eine Information, ... Da diese activation records klassischerweise auf einem Stack verwaltet werden, kann man hier Stackspace sparen - Endrekursion ist damit genauso effizient wie eine klassische Iteration mit einem Sprung. ...
    (de.comp.lang.java)
  • Re: Please Explain where will the struct be stored if it is declared inside the Class
    ... forget about structs for a second. ... can be stored either on the stack, or on the heap. ... First, think about the stack. ... A struct would act exactly the same as any of these decimals and ints. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is MSDN wrong? or I made a mistake? about static member function
    ... the heap" or some such reference. ... shouldn't we have a uniform notation? ... You can tell a heap object from a stack object by ... the result of trying to build a compiler on a tiny computer by someone who wasn't a very ...
    (microsoft.public.vc.mfc)