Research V5 development
authorKen Thompson <ken@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
committerKen Thompson <ken@research.uucp>
Tue, 26 Nov 1974 23:13:21 +0000 (18:13 -0500)
Work on file usr/sys/ken/malloc.c

Synthesized-from: v5

usr/sys/ken/malloc.c [new file with mode: 0644]

diff --git a/usr/sys/ken/malloc.c b/usr/sys/ken/malloc.c
new file mode 100644 (file)
index 0000000..58b96e3
--- /dev/null
@@ -0,0 +1,64 @@
+#
+/*
+ *     Copyright 1973 Bell Telephone Laboratories Inc
+ */
+
+struct map {
+       char *m_size;
+       char *m_addr;
+};
+
+malloc(mp, size)
+struct map *mp;
+{
+       register int a;
+       register struct map *bp;
+
+       for (bp = mp; bp->m_size; bp++) {
+               if (bp->m_size >= size) {
+                       a = bp->m_addr;
+                       bp->m_addr =+ size;
+                       if ((bp->m_size =- size) == 0)
+                               do {
+                                       bp++;
+                                       (bp-1)->m_addr = bp->m_addr;
+                               } while ((bp-1)->m_size = bp->m_size);
+                       return(a);
+               }
+       }
+       return(0);
+}
+
+mfree(mp, size, aa)
+struct map *mp;
+{
+       register struct map *bp;
+       register int t;
+       register int a;
+
+       a = aa;
+       for (bp = mp; bp->m_addr<=a && bp->m_size!=0; bp++);
+       if (bp>mp && (bp-1)->m_addr+(bp-1)->m_size == a) {
+               (bp-1)->m_size =+ size;
+               if (a+size == bp->m_addr) {
+                       (bp-1)->m_size =+ bp->m_size;
+                       while (bp->m_size) {
+                               bp++;
+                               (bp-1)->m_addr = bp->m_addr;
+                               (bp-1)->m_size = bp->m_size;
+                       }
+               }
+       } else {
+               if (a+size == bp->m_addr && bp->m_size) {
+                       bp->m_addr =- size;
+                       bp->m_size =+ size;
+               } else if (size) do {
+                       t = bp->m_addr;
+                       bp->m_addr = a;
+                       a = t;
+                       t = bp->m_size;
+                       bp->m_size = size;
+                       bp++;
+               } while (size = t);
+       }
+}