一个进程有一个堆栈还是一个线程一个堆栈还是一个函数一个堆栈?

解决方案 »

  1.   

    看看操作系统吧
    如果我记得不错的话
    一个process有一个堆,一个堆中有N个栈
    一个thread有一个栈
    Each new thread receives its own stack space, consisting of both committed and reserved memory. The system will commit one page blocks from the reserved stack memory as needed, until the stack cannot grow any farther.
    The default size for committed and reserved memory is specified in the executable file header. The default reserved memory is one megabyte. To specify a different default stack size, use the STACKSIZE statement in the module definition (.DEF) file. Your linker may also support a command-line option for setting the stack size. For more information, see the documentation included with your linker.Threads that call the C run-time library or the Windows API must allow sufficient stack space for use of these functions. Do not lower the reserved stack size below 64 KB.To increase the amount of stack space which is to be initially committed for a thread, specify the value in the dwStackSize parameter of the CreateThread or CreateRemoteThread function. This value is rounded to the nearest page. The call to create the thread fails if there is not enough memory to commit or reserve the number of bytes requested. If dwStackSize is smaller than the default reserve size, the new thread uses the default reserve size. If dwStackSize is larger than the default reserve size, the reserve size is rounded up to the nearest multiple of 1 MB.
    Windows Server 2003 and Windows XP:  If the dwCreationFlags parameter of CreateThread or CreateRemoteThread is STACK_SIZE_PARAM_IS_A_RESERVATION, the dwStackSize parameter specifies the amount of stack space which is to be initially reserved for the thread.
    The stack is freed when the thread terminates.
      

  2.   

    一个线程有一个stack,stack是用来保存函数调用返回地址,如果线程没有自己的stack,那么多个线程调用函数不就互相影响。函数没有stack
      

  3.   

    HANDLE HeapCreate(
      DWORD flOptions,      // heap allocation flag
      DWORD dwInitialSize,  // initial heap size
      DWORD dwMaximumSize   // maximum heap size
    );
     
    一个进程可以通过它创建私有堆。。一个进程可以有多个堆。