我找到了以下函数here,并希望在MinGW下编译它:
size_t stackavail()
{
static unsigned StackPtr;
__asm mov [StackPtr],esp
static MEMORY_BASIC_INFORMATION mbi;
VirtualQuery((PVOID)StackPtr,&mbi,sizeof(mbi));
return StackPtr-(unsigned)mbi.AllocationBase;
}
我尝试修改上面的代码并设法编译并运行它:
size_t stackavail()
{
static unsigned StackPtr;
__asm__ ("movl %%esp, %0\n\t" : "=r" (StackPtr) );
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery((PVOID)StackPtr, &mbi, sizeof(mbi));
return StackPtr-(unsigned)mbi.AllocationBase;
}
但我有疑问。这是对的吗?还有其他办法吗?
答案 0 :(得分:0)
您可以摆脱内联ASM,使用
void* StackPtr = &StackPtr;