- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ,
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.
Armando
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That will tell you after the error, it will not tell the program prior to error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As Jim Dempsey said that will not avoid the stack overflow. I liked stackavail() in Watcom ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am testing this code:
#include "windows.h"
size_t stackavail(void)
{
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page