我有以下代碼,當我運行它時,將1000字節傳遞給函數中的參數,結構MEMORY_BASIC_INFORMATION
沒有使用任何變量,它們都保持爲0.我想知道這是否應該是?爲什麼這個結構的變量在被調用時沒有被填滿?
public unsafe static bool CheckForSufficientStack(long bytes)
{
MEMORY_BASIC_INFORMATION stackInfo = new MEMORY_BASIC_INFORMATION();
IntPtr currentAddr = new IntPtr((uint)&stackInfo - 4096);
VirtualQuery(currentAddr, ref stackInfo, sizeof(MEMORY_BASIC_INFORMATION));
return ((uint)currentAddr.ToInt64() - stackInfo.AllocationBase) > (bytes + STACK_RESERVED_SPACE);
}
private const long STACK_RESERVED_SPACE = 4096 * 16;
[DllImport("kernel32.dll")]
private static extern int VirtualQuery(
IntPtr lpAddress,
ref MEMORY_BASIC_INFORMATION lpBuffer,
int dwLength);
private struct MEMORY_BASIC_INFORMATION
{
internal uint BaseAddress;
internal uint AllocationBase;
internal uint AllocationProtect;
internal uint RegionSize;
internal uint State;
internal uint Protect;
internal uint Type;
}
我在Core Duo 2.0Ghz上運行Vista Enterprise X64。
http://www.pinvoke.net/default.aspx/kernel32.virtualquery – 2010-07-04 16:10:18