qc.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
HALLOC.C
                                             Up Contents Index Back
────────────────────────────────────────────────────────────────────────────
 
/* HALLOC.C illustrates dynamic allocation of huge memory using functions:
 *      halloc          hfree
 */
 
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
 
void main()
{
    char _huge *bigbuf, _huge *p;
    long count = 100000L;
 
    /* Allocate huge buffer (100,000 bytes). */
    bigbuf = (char _huge *)halloc( count, sizeof( char ) );
    if( bigbuf == NULL )
    {
        printf( "Insufficient memory" );
        exit( 1 );
    }
 
    /* Fill the buffer with characters. */
    for( p = bigbuf; count; count--, p++ )
        *p = (char)(count % 10) + '0';
 
    /* Free huge buffer. */
    hfree( bigbuf );
    exit( 0 );
}