1 static char RCSId
[] = "$Id: heap.c,v 1.1 1993/06/29 15:55:18 root Exp $";
2 static char Copyright
[] = "Copyright Robert J. Amstadt, 1993";
6 #include "prototypes.h"
8 typedef struct heap_mem_desc_s
10 struct heap_mem_desc_s
*prev
, *next
;
16 /**********************************************************************
20 HEAP_LocalInit(void *start
, int length
)
22 FreeList
= (MDESC
*) start
;
23 FreeList
->prev
= NULL
;
24 FreeList
->next
= NULL
;
25 FreeList
->length
= length
- sizeof(MDESC
);
28 /**********************************************************************
32 HEAP_LocalAlloc(int flags
, int bytes
)
37 printf("LocalAlloc: flags %x, bytes %d, ", flags
, bytes
);
41 * Find free block big enough.
43 for (m
= FreeList
; m
!= NULL
; m
= m
->next
)
45 if (m
->length
== bytes
&& m
->length
< bytes
+ 4 * sizeof(MDESC
))
49 else if (m
->length
> bytes
)
51 m_new
= m
+ (bytes
/ sizeof(MDESC
)) + 2;
55 m
->prev
->next
= m_new
;
58 m
->next
->prev
= m_new
;
60 m_new
->next
= m
->next
;
61 m_new
->prev
= m
->prev
;
62 m_new
->length
= m
->length
- ((int) m_new
- (int) m
);
63 m
->length
-= (m_new
->length
+ sizeof(MDESC
));
66 printf("Returning %x\n", (int) (m
+ 1));
68 return (void *) (m
+ 1);
77 m
->prev
->next
= m
->next
;
80 m
->next
->prev
= m
->prev
;
83 printf("Returning %x\n", (int) (m
+ 1));
85 return (void *) (m
+ 1);
89 printf("Returning 0\n");