blob: 59c2af1df8e888ca6213418c300014bb219e4de9 [file] [log] [blame]
Jack Jansendffa1231995-08-31 14:18:30 +00001
2 What is this?
3 -------------
4This package is a memory allocator for the Macintosh. It was initially
5implemented for use with the MetroWerks CodeWarrior compiler on the
6PowerPC Mac, but may also be useful (in a more limited way) for use
7with MW 68K or Think compilers.
8
9This is distribution 1.0, dated April 19, 1995.
10
11 How does it work?
12 -----------------
13Actually, 99% of the code comes straight from the old old BSD-unix
14"fast malloc", only the interface to the low-level memory allocator
15and the handling of large blocks is different. The allocator follows
16one of two strategies, based upon block size:
17- for small blocks (anything up to 8K, as distributed), the size is
18 rounded up to the next power of two, and that much is
19 allocated. Realloc, etc. understand about this. Small blocks are
20 packed into 8K segments.
21- Larger blocks are allocated directly using NewPtr().
22
23 Why should I want it?
24 ---------------------
25The reason for writing this is that I've had serious problems with MW
26malloc, especially in one piece of software, the Python
27interpreter. Python is a very-high level interpreted language, and
28spends very large amounts of time in malloc. Moreover, it reallocs()
29like there's no tomorrow, and allocates and frees tiny and huge blocks
30intermixedly. After some time running, this caused two things (using
31the original MW malloc): memory useage grew exponentially and so did
32runtime. MetroWerks have tried to be helpful, but I have been unable
33to provide them with simple sample-programs that showed the problem:
34it seems to be something to do with fragmentation and only happens
35under very heavy use.
36
37The 68K MW malloc has the same problems, and the Think C malloc
38has a similar one: it shows the same growth problem but not the
39increase in runtime.
40
41Two additional reasons for using it:
42- It is blindingly fast.
43- It has pretty good range checking and such (enabled with a #define),
44 so it'll help you catch various programming errors like referencing
45 outside the bounds of the malloced block.
46
47One reason for not using it:
48- It is rather wasteful of memory. Small blocks, on average, occupy
49 25% more memory than they need, and the allocation in 8K chunks
50 wastes another 50K (on average). Also, memory is never returned from
51 malloc()s pool to the Memory Manager.
52
53 How do I use it?
54 ----------------
55For MW PPC: simply add the sources to your project. Due to the way the
56linker works all mallocs will use the new malloc, even the malloc
57calls that come from the libraries (if I'm informaed correctly).
58
59For MW 68K: ditto, only supposedly the library malloc calls will still
60use the original malloc. The two packages don't bite each other,
61however, so there shouldn't be any problems.
62
63For Think: more work, but you can rebuild the ANSI library with this
64malloc, since the Think distribution contains everything you need for
65this.
66
67 Is that all?
68 ------------
69
70Yes. Let me finish off by asking that you send bug reports, fixes,
71enhancement, etc to me at the address below.
72
73 Jack Jansen
74 Centrum voor Wiskunde en Informatica
75 Kruislaan 413
76 1098 SJ Amsterdam
77 the Netherlands
78
79 <Jack.Jansen@cwi.nl>
80