_stackavail

Description

Gets the size of the stack available.

#include <malloc.h> Required only for function declarations  

size_t _stackavail( void );

Remarks

The _stackavail function returns the approximate size (in bytes) of the stack space available for dynamic memory allocation with _alloca.

Return Value

The _stackavail function returns the size in bytes as an unsigned integer value.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

Example

/* ALLOCA.C: Checks the stack space available before and after using

* _alloca to allocate space on the stack. As _alloca is incompatible

* with optimizing, compile with optimizations disabled (/Od).

*/

#include <malloc.h>

#include <stdio.h>

void main( void )

{

char *buffer;

printf( "Bytes available on stack: %u\n", _stackavail() );

/* Allocate memory for string. */

buffer = _alloca( 120 * sizeof( char ) );

printf( "Enter a string: " );

gets( buffer );

printf( "You entered: %s\n", buffer );

printf( "Bytes available on stack: %u\n", _stackavail() );

}

Output

Bytes available on stack: 2028

Enter a string: How much stack space will this string take?

You entered: How much stack space will this string take?

Bytes available on stack: 1902