_memmax

Description

Finds the size of the largest contiguous memory block.

#include <malloc.h>

size_t _memmax( void );

Remarks

The _memmax function returns the size (in bytes) of the largest contiguous block of memory that can be allocated from the near heap (i.e., the default data segment). Calling _nmalloc with the value returned by the _memmax function will succeed as long as _memmax returns a nonzero value.

Return Value

The function returns the block size, if successful. Otherwise, it returns 0, indicating that nothing more can be allocated from the near heap.

Compatibility

Standards:None

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

32-Bit:None

See Also

malloc functions, _msize functions

Example

/* MEMMAX.C: This program uses _memmax and _nmalloc to allocate

* the largest block of memory available in the near heap.

*/

#include <stddef.h>

#include <malloc.h>

#include <stdio.h>

void main( void )

{

size_t contig;

char *p;

/* Determine contiguous memory size */

contig = _memmax();

printf( "Largest block of available memory is %u bytes long\n", contig );

if( contig )

{

p = _nmalloc( contig * sizeof( int ) );

if( p == NULL )

printf( "Error with malloc (should never occur)\n" );

else

{

printf( "Maximum allocation succeeded\n" );

free( p );

}

}

else

printf( "Near heap is already full\n" );

}

Output

Largest block of available memory is 60844 bytes long

Maximum allocation succeeded