Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
26 Views

stackavail() with Intel C under Windows ??

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

0 Kudos
8 Replies
Highlighted
Moderator
26 Views

check this: http://support.microsoft.com/kb/315937. same method works for IntelC.

Jennifer

0 Kudos
Highlighted
26 Views

That will tell you after the error, it will not tell the program prior to error.

0 Kudos
Highlighted
26 Views

As Jim Dempsey said that will not avoid the stack overflow.  I liked  stackavail()  in Watcom ...

0 Kudos
Highlighted
26 Views

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.  

0 Kudos
Highlighted
Valued Contributor II
26 Views

Armando's case could be a unique one. In case of very large data sets ( greater than 64MB ) processed by a recursive algorithms, like Merge Sort or Strassen's matrix multiplication, I simply set Stack Reserve and Commit values to 1073741824 ( 1GB ). It doesn't matter what verifications you have on a 32-bit platform it is impossible to allocate / use more than 2GB of memory ( unless AWE is used on a Windows 32-bit platform ). >>...I have a dangerous recursive function... What about some generic details on what it actually does?
0 Kudos
Highlighted
26 Views

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.

0 Kudos
Highlighted
Valued Contributor II
26 Views

Thanks, Armando. My test-case for verification of a maximum number recusrive calls for a very simple function is as follows: ... // Evaluation of Max Number of Recursive calls // These numbers could be different on another computer! // Windows XP - DEBUG= 4774 - RELEASE= 86172 // Windows XP with MinGW - DEBUG=130172 - RELEASE=130172 // Pocket PC 2003 - DEBUG= 817 - RELEASE= 1000 // Smartphone 2003 - DEBUG= 817 - RELEASE= 1000 // Windows Mobile 5 - DEBUG= 817 - RELEASE= 1000 // Windows XP with BCC - DEBUG= 64597 - RELEASE= 64597 // Compact OS ( 16-bit ) with TCC - DEBUG= 5898 - RELEASE= 5898 // before the test application crashes void GetMaxNumOfRecursiveCalls( int iCount ); void GetMaxNumOfRecursiveCalls( int iCount ) { if( iCount == -1 ) return; printf( "%ld\n", ++iCount ); GetMaxNumOfRecursiveCalls( iCount ); } int main( void ) { ... GetMaxNumOfRecursiveCalls( 0 ); ... } I'll verify how your function is working with different C++ compilers.
0 Kudos
Highlighted
26 Views

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

0 Kudos