CreateThread
分配的堆栈空间是否可能干扰VirtualAlloc
的使用?我找不到在哪里堆栈空间允许被分配的精确解释任何讨论或文档...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如何在给定的进程中分配堆栈空间?
+1这是不可想象的 - 操作系统在启动时会很快崩溃,甚至没有时间来蓝屏。 – 2012-08-11 05:20:05
谢谢你的回答。也许“干涉”对于这个问题来说是一个严厉的话。我所要求的基本上是,如果'CreateThread',可以在任何地方分配堆栈空间 - 并且你回答了这个问题。通过“干涉”,我问是否可以将流程的虚拟地址空间分割出来(但是,现在我想到了它,还有什么地方可以分配它?)。所以,看起来好像随机线程分配会导致没有自定义分配器可以解析的碎片。 – defube 2012-08-11 05:58:38
我喜欢我自己介绍的“AddrSpaceUtilization”概念。这是所有'VirtualAlloc'分配的大小总和与地址空间本身大小的比率。我在Windows上使用32位进程的经验表明,当此值小于85-90%时,所有工作都或多或少地正常。当它超过90%时,出现各种问题。 – 2012-08-11 06:46:33