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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
--- /usr/ports/devel/cocktail/work/cocktail-9309//./reuse/c/rMemory.c Tue Feb 15 14:26:42 1994
+++ ./reuse/c/rMemory.c Fri Sep 10 13:35:03 2004
@@ -49,14 +49,16 @@
*/
/* Ich, Doktor Josef Grosch, Informatiker, Sept. 1987 */
-
-static char rcsid [] = "$Id: rMemory.c,v 1.14 1993/08/18 15:01:05 grosch rel $";
+# include <sys/cdefs.h>
+# include <sys/cdefs.h>
+__RCSID("$Id: rMemory.c,v 1.14 1993/08/18 15:01:05 grosch rel $");
# include "ratc.h"
# include "rMemory.h"
# include "rSystem.h"
# include "General.h"
# include <stdio.h>
+# include <stdlib.h>
# define MinSizeSmallBlock 4
# define MaxSizeSmallBlock 62 /* 64 - 2 */
@@ -75,6 +77,7 @@
typedef cardinal tSmallBlockRange;
typedef cardinal tLargeBlockRange;
+#ifndef FREEBSD
static tBlockPtr SmallChain [MaxSizeSmallBlock + 1] = { 0,
NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL,
NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL,
@@ -89,16 +92,21 @@
NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL,
NIL, NIL, NIL, NIL,
};
+#endif
static char * PoolFreePtr = 0;
static char * PoolEndPtr = 0;
char * Alloc (ByteCount)
register unsigned long ByteCount;
-
/* Returns a pointer to dynamically allocated */
/* space of size 'ByteCount' bytes. */
{
+# ifdef FREEBSD
+ /* FreeBSD has an efficient memory allocator */
+ /* The cocktail code assumes that allocated space is zeroed */
+ return (char*) calloc(1UL,ByteCount);
+#else
ByteCount = (ByteCount + yyMaxAlign - 1) & yyAlignMasks [yyMaxAlign];
if (ByteCount <= MaxSizeSmallBlock) { /* handle small block */
@@ -187,6 +195,7 @@
return (char *) CurrentBlock;
}
}
+#endif /*FREEBSD */
}
void Free (ByteCount, a)
@@ -198,6 +207,9 @@
/* released. */
{
+#ifdef FREEBSD
+ free(a);
+#else
register tBlockPtr BlockPtr;
register tLargeBlockRange ChainNumber;
@@ -214,10 +226,12 @@
BlockPtr->Size = ByteCount;
LargeChain [ChainNumber] = BlockPtr;
}
+#endif /*FREEBSD */
}
void InitrMemory ()
{
+#ifndef FREEBSD
register int i;
for (i = MinSizeSmallBlock; i <= MaxSizeSmallBlock; i += 2) {
@@ -226,6 +240,7 @@
for (i = MinSizeLargeBlockLog; i <= MaxSizeLargeBlockLog; i ++) {
LargeChain [i] = NIL;
}
+#endif
MemoryUsed = 0;
PoolFreePtr = 0;
PoolEndPtr = 0;
|