Reference Section
_far_avail {
void far *block;
long int heap_left;
block = (char *)_far_malloc(0x400);
heap_left = _far_avail ();
_far_free(block);
}
#include <inline.h>
{
void far *buffer;
...
buffer = (char *)_far_malloc (0x400);
far_avail();/* DX;AX = bytes left on heap */
...
_far_free(buffer);
}
Source file MAFAVAIL.ASM ASM equiv FAR_AVAIL
{
char far *fblk;
...
fblk = (char *)_far_calloc(20,1); /* allocate a block and
initialize to 0 */
_fstr_cpy(fblk, "hello\n\r");/* copy string to far block */
_fput_str(fblk);/* display string from far block */
...
}
Because of variations between compilers, an inline version
of this function has not been provided.
Source file _MAFCALC.ASM ASM equiv FAR_CALLOC
{
void far *pointer;
...
pointer = (char *)_far_malloc (0x10);
if (pointer == NULL) /* allocate 16 byte block */
{
/* handle the error */
}
...
if (_far_free (pointer) == -1) /* free block */
{
/* handle the error */
}
}
Because of variations between compilers, an inline version
of this function has not been provided.
Source file _MAFFREE.ASM ASM equiv FAR_FREE
{
char far *fblk;
...
fblk = (char far *)_far_malloc(20);/* allocate far block */
_fstr_cpy(fblk, "hello\n\r");/* copy string to far block */
_fput_str(fblk); /* display str from far block */
...
}
Because of variations between compilers, an inline version
of this function has not been provided.
Source file _MAFMALC.ASM ASM equiv FAR_MALLOC
{
void far *block;
long int heap_largest;
block = (char *)_far_malloc (0x400);
heap_largest = _far_max ();
...
_far_free (block);
}
#include <inline.h>
{
void far *buffer;
...
buffer = (char *)_far_malloc (0x400);
far_max();/* DX;AX = largest block avail */
...
_far_free(buffer);
}
Source file None ASM equiv FAR_MAX
{
void far *pointer, far *extra_ptr;
pointer = _far_malloc(0x10);/* allocate 16 byte block */
if (pointer == NULL)
{
/* error allocating block */
}
...
extra_ptr = _far_realloc (pointer, 0x20);
/* reallocate block to 32 bytes */
if (extra_ptr == NULL)
{
/* error allocating block */
}
pointer = extra_ptr; /* reassign block pointer */
...
}
Because of variations between compilers, an inline version
of this function has not been provided.
Source file _MAFRALC.ASM ASM equiv FAR_REALLOC
{
void *block;
unsigned int heap_left;
block = _near_malloc(0x400);
heap_left = _near_avail();
_near_free(block);
}
#include <inline.h>
{
void *block;
...
block = _near_malloc(0x400); /* AX -> allocated block */
near_avail();/* AX = number of bytes available */
...
_near_free (block);
...
}
Source file MANAVAIL.ASM ASM equiv NEAR_AVAIL
{
char * nblk;
...
nblk = (char *)_near_calloc(20,1); /* allocate a block and
initialize to 0 */
_str_cpy(nblk, "hello\n\r");/* copy string to block */
_put_str(nblk); /* display string in block */
...
}
Because of variations between compilers, an inline version
of this function has not been provided.
Source file _MANCALC.ASM ASM equiv NEAR_CALLOC
{
void *pointer;
...
pointer = _near_malloc(0x100); /* allocate 100 bytes */
if (pointer == NULL)
{
/* handle the error */
}
...
if (_near_free(pointer) == -1)
/* free block pointer to by pointer */
{
/* handle the error */
}
...
}
#include <inline.h>
Because of variations between compilers, an inline version
of this function has not been provided.
Source file _MANFREE.ASM ASM equiv NEAR_FREE
{
char *nblk;
...
nblk = (char *)_near_malloc(20);/* allocate a block */
_str_cpy(nblk, "hello\n\r"); /* copy string */
_put_str(nblk); /* display block */
...
}
#include <inline.h>
Because of the variations between compilers, an inline version
of this function has not been provided.
Source file _MANMALC.ASM ASM equiv NEAR_MALLOC
{
void *block;
unsigned int heap_largest;
block = _near_malloc(0x400);
heap_largest = _near_max();
_near_free(block);
}
#include <inline.h>
{
void *block;
...
block = _near_malloc(0x400); /* AX -> allocated block */
near_max(); /* AX = size of largest block */
...
_near_free(block);
}
Source file MANMAX.ASM ASM equiv NEAR_MAX
{
void *block, *extra_blk;
...
block = _near_malloc(0x100); /*allocate a block of 100 bytes*/
if (block == NULL)
{
/* error allocating block */
}
...
extra_blk = _near_realloc(block, 0x200);
if (extra_blk == NULL)
{
/* error resizing block */
}
...
block = extra_blk;/* reassign block pointer */
}
#include <inline.h>
Because of the variations between compilers, an inline version
of this function has not been provided.
Source file _MANRALC.ASM ASM equiv NEAR_REALLOC
{
segaddr heapseg;
unsigned int heapsize, heapleft;
...
_rel_init (heapseg, heapsize);
heapleft = _rel_avail (heapseg);
...
}
#include <inline.h>
{
segaddr heapseg;
unsigned int heapsize;
...
mov es,heapseg/* ES = segment for rel heap */
mov ax,heapsize/* AX = size of rel heap */
rel_init (); /* initialize relative heap */
rel_avail (); /* AX = bytes avail on heap */
...
}
Source file _MARAVAL.ASM ASM equiv REL_AVAIL
{
void far *buffer;
segaddr heapseg;
unsigned int heapsize;
...
_rel_init (heapseg, heapsize);
/* allocate memory for one window */
buffer = _rel_calloc (heapseg, 1, sizeof(sawin));
if (buffer == NULL)
{
/* Handle the error */
}
...
}
#include <inline.h>
{
segaddr heapseg;
unsigned int heapsize, size = sizeof(sawin);
...
mov es,heapseg
mov ax,heapsize
rel_init ();
mov ax,size
mov cx,1
rel_calloc (); /* DI -> allocated block */
jc label_010/* if unable to allocate block */
...
label_010:
}
Source file _MARCALC.ASM ASM equiv REL_CALLOC
{
void far *buffer;
segaddr heapseg;
...
buffer = _rel_malloc (heapseg, 500);
if (buffer == NULL)
{
/* Handle the error */
}
...
_rel_free (buffer);
}
#include <inline.h>
{
segaddr heapseg;
unsigned int heapsize, bufsize;
...
mov es,heapseg/* ES = segment for rel heap */
mov ax,heapsize/* AX = size of rel heap */
rel_init ();
mov ax,bufsize/* AX = size block to allocate */
rel_malloc (); /* DI = offset of block */
jc rel_free_010/* if error allocating block */
... /* if successful */
rel_free (); /* free mem block at ES:DI */
jc rel_free_010/* if an error occurred */
... /* if successful */
rel_free_010:
}
Source file _MARFREE.ASM ASM equiv REL_FREE
{
segaddr heapseg;
unsigned int heapsize;
...
_rel_init (heapseg, heapsize);
...
}
#include <inline.h>
{
segaddr heapseg;
unsigned int heapsize;
...
mov es,heapseg/* ES = segment for rel heap */
mov ax,heapsize/* AX = size of rel heap */
rel_init (); /* initialize relative heap */
...
}
Source file _MARNITC.ASM ASM equiv REL_INIT
{
void far *buffer;
segaddr heapseg;
unsigned int heapsize, bufsize;
...
_rel_init (heapseg, heapsize);
buffer = _rel_malloc (heapseg, bufsize);
if (buffer == NULL)
{
/* Handle the error */
}
...
}
#include <inline.h>
{
segaddr heapseg;
unsigned int heapsize, bufsize;
...
mov es,heapseg/* ES = segment for rel heap */
mov ax,heapsize/* AX = size of rel heap */
rel_init ();
mov ax,bufsize/* AX = size for block */
rel_malloc (); /* DI = offset of block */
jc main_010/* if error allocating block */
... /* if successful */
main_010:
...
}
Source file _MARMALC.ASM ASM equiv REL_MALLOC
{
segaddr heapseg;
unsigned int heapsize, heapmax;
...
_rel_init (heapseg, heapsize);
heapmax = _rel_max (heapseg);
...
}
#include <inline.h>
{
segaddr heapseg;
unsigned int heapsize;
...
mov es,heapseg/* ES = segment for rel heap */
mov ax,heapsize/* AX = size of rel heap */
rel_init (); /* initialize in real heap */
rel_max (); /* AX = size of block */
...
}
Source file _MARMAX.ASM ASM equiv REL_MAX
{
void far *pointer1, far *pointer2;
segaddr heapseg;
unsigned int heapsize, bufsize, newsize;
...
_rel_init (heapseg, heapsize);
pointer1 = _rel_malloc (heapseg, bufsize);
if (pointer1 == NULL)
{
/* Handle the error */
}
...
pointer2 = _rel_realloc (pointer1, newsize);
if (pointer2 == NULL)
{
/* handle the error */
pointer2 = pointer1;
}
...
_rel_free (pointer2);
}
#include <inline.h>
{
segaddr heapseg;
unsigned int heapsize, bufsize, newsize;
...
mov es,heapseg
mov ax,heapsize
rel_init (); /* initialize relative heap */
mov ax,bufsize
rel_malloc (); /* DI = offset of block */
jc label_020/* if error allocating memory */
...
mov ax,newsize
rel_realloc (); /* DI = offset adjusted block */
jc label_010/* if unable to expand block */
...
label_010:
rel_free ();
jnclabel_020/* if successful */
... /* if an error occurred */
label_020:
...
}
Source file _MARRALC.ASM ASM equiv REL_REALLOC