【发布时间】:2012-08-08 07:47:33
【问题描述】:
CreateThread分配的栈空间会不会干扰VirtualAlloc的使用?我找不到任何讨论或文档准确解释允许分配堆栈空间的位置...
以下更准确地说明了我的问题:
uint8_t *baseA = (uint8_t*)VirtualAlloc(NULL,1,MEM_RESERVE,PAGE_NOACCESS);
// Create a thread with the default stack size
HANDLE hThread = CreateThread(NULL,0,SomeThreadProc,NULL,NULL,NULL);
// Possibly create even more threads here.
// Can this ever fail in the absence of other allocators? It doesn't here...
uint8_t *baseB = (uint8_t*)VirtualAlloc(NULL,1,MEM_RESERVE,PAGE_NOACCESS);
// Furthermore, in this test, baseB-baseA == 65536 (unless the debugger did something),
// so nothing appeared between baseA and baseB... not even enough space for the
// full 64kb of wastage, as baseA points to 4096 bytes by itself
如果它确实实际上使用了VirtualAlloc 的一些类似物,有没有办法改变Windows 在给定进程中分配堆栈空间的方式?
【问题讨论】:
标签: c++ winapi virtual-memory