aboutsummaryrefslogtreecommitdiff
path: root/DALLOC.C
blob: 7db858c3411007b3203b4b41c62134a10dc6d9c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*--------------------------------------------------------------*/
/*								*/
/*		dalloc.c  					*/
/*								*/
/*	lets you specify flags but remembers the length for	*/
/*	freeing.						*/
/*--------------------------------------------------------------*/

#include <exec\types.h>
#include <exec\nodes.h>
#include <exec\memory.h>

/* first 4 bytes of allocated area contain the length of the area.
This length is the number of bytes allocated by AllocMem, ie includes
the 4 bytes for itself */
    
/* size in bytes */
UBYTE *DAlloc(size,flags) LONG size; USHORT flags; {
    LONG *p;
    LONG asize = size+4;
    p = (LONG *)AllocMem(asize,flags);
    if (p==NULL){
	return((UBYTE *)p);
	}
    *p++ = asize;	/* post-bump p to point at clients area*/
    return((UBYTE *)p);
    }
    
UBYTE *ChipAlloc(size) LONG size; {
    return(DAlloc(size,MEMF_PUBLIC|MEMF_CHIP));
    }
    
DFree(p) UBYTE *p; {
    if (p!=NULL) {
	p -= 4;
	return(FreeMem(p, *((LONG *)p))); 
	}
    }