Doxygen Source Code Documentation
malloc.c File Reference
#include "string.h"
Go to the source code of this file.
Data Structures | |
struct | mem |
Defines | |
#define | STACKMIN 512 |
#define | MINBLK (2*sizeof(struct mem) + 16) |
#define | F _malloc_free_ |
#define | SBGULP 8192 |
#define | Char void |
#define | Unsigned size_t |
#define | Int int |
Typedefs | |
typedef mem | mem |
Functions | |
Char * | malloc (register Unsigned size) |
void | free (Char *f) |
Char * | realloc (Char *f, Unsigned size) |
Variables | |
mem * | F |
Define Documentation
|
|
|
|
|
Definition at line 38 of file malloc.c. Referenced by malloc(). |
|
Definition at line 26 of file malloc.c. Referenced by malloc(). |
|
Definition at line 28 of file malloc.c. Referenced by malloc(). |
|
|
|
|
Typedef Documentation
|
|
Function Documentation
|
Definition at line 106 of file malloc.c. References Char, mem::len, mem::next, p, q, and r.
00108 { 00109 mem *p, *q, *r; 00110 char *pn, *qn; 00111 00112 if (!f) return; 00113 q = (mem *) ((char *)f - sizeof(mem)); 00114 qn = (char *)f + q->len; 00115 for (p = F, r = (mem *) &F; ; r = p, p = p->next) { 00116 if (qn == (Char *) p) { 00117 q->len += p->len + sizeof(mem); 00118 p = p->next; 00119 } 00120 pn = p ? ((char *) (p+1)) + p->len : 0; 00121 if (pn == (Char *) q) { 00122 p->len += sizeof(mem) + q->len; 00123 q->len = 0; 00124 q->next = p; 00125 r->next = p; 00126 break; 00127 } 00128 if (pn < (char *) q) { 00129 r->next = q; 00130 q->next = p; 00131 break; 00132 } 00133 } 00134 } |
|
Definition at line 53 of file malloc.c. References Char, Int, mem::len, MINBLK, mem::next, p, q, r, SBGULP, top, and Unsigned.
00055 { 00056 register mem *p, *q, *r, *s; 00057 unsigned register k, m; 00058 extern Char *sbrk(Int); 00059 char *top, *top1; 00060 00061 size = (size+7) & ~7; 00062 r = (mem *) &F; 00063 for (p = F, q = 0; p; r = p, p = p->next) { 00064 if ((k = p->len) >= size && (!q || m > k)) { 00065 m = k; 00066 q = p; 00067 s = r; 00068 } 00069 } 00070 if (q) { 00071 if (q->len - size >= MINBLK) { /* split block */ 00072 p = (mem *) (((char *) (q+1)) + size); 00073 p->next = q->next; 00074 p->len = q->len - size - sizeof(mem); 00075 s->next = p; 00076 q->len = size; 00077 } 00078 else 00079 s->next = q->next; 00080 } 00081 else { 00082 top = (Char *)(((long)sbrk(0) + 7) & ~7); 00083 if (F && (char *)(F+1) + F->len == top) { 00084 q = F; 00085 F = F->next; 00086 } 00087 else 00088 q = (mem *) top; 00089 top1 = (char *)(q+1) + size; 00090 if (sbrk((int)(top1-top+SBGULP)) == (Char *) -1) 00091 return 0; 00092 r = (mem *)top1; 00093 r->len = SBGULP - sizeof(mem); 00094 r->next = F; 00095 F = r; 00096 q->len = size; 00097 } 00098 return (Char *) (q+1); 00099 } |
|
Definition at line 142 of file malloc.c. References Char, free, mem::len, malloc, mem::next, p, q, and Unsigned.
00144 { 00145 mem *p; 00146 Char *q, *f1; 00147 Unsigned s1; 00148 00149 if (!f) return malloc(size); 00150 p = (mem *) ((char *)f - sizeof(mem)); 00151 s1 = p->len; 00152 free(f); 00153 if (s1 > size) 00154 s1 = size + 7 & ~7; 00155 if (!p->len) { 00156 f1 = (Char *)(p->next + 1); 00157 memcpy(f1, f, s1); 00158 f = f1; 00159 } 00160 q = malloc(size); 00161 if (q && q != f) 00162 memcpy(q, f, s1); 00163 return q; 00164 } |
Variable Documentation
|
|