I am porting and old project from Watcom C/C++ to Intel C. I have a dangerous recursive function. With Watcom I checked the free stack to predict and statck overflow using stackavail() .
Please, how can I do that with Intel C, under Windows ?
Thanks to all.
I am testing this code:
static unsigned StackPtr; // top of stack ptr
__asm mov [StackPtr],esp // mov pointer to top of stack
static MEMORY_BASIC_INFORMATION mbi; // page range
VirtualQuery((PVOID)StackPtr,&mbi,sizeof(mbi)); // get range
return StackPtr-(unsigned)mbi.AllocationBase; // subtract from top (stack grows downward on win)
So far looks working.
Hi Serguey, My project target is Win32. It is and old implementation of a recursive fill, in memory for big bitmaps, with very complex borders. I could be over concerned because default stack size for win32 is 1 MB. In the past I got into some complex topologies that make the recursive fill stop before completion. Using stackavail() the system never crashed, it simply stoped and emited a warning. I am trying to have the same safeguard with the Intel implementation. The function stackavail() that I posted looks like to be working fine so far.
Sergey, I am afraid it is not a portable solution... It is system dependent (it works with win32 and hope with win64, not yet tested) and needs support for inlined "__asm" . Let me know about your results and considerations. Thanks