MOSCH logo

Mac OS Classic Handles

This is MOSCH, a small porting and convenience library for UNIX programmers. It is released under the ZLib license, which is liberal, nonviral, and hence permissive of commercial use.

I wrote MOSCH for two reasons:

  1. As a convenience for UNIX programmers porting old Mac code. (Well... it could happen!)
  2. As a convenience for UNIX programmers wanting resizeable memory refs that can be passed around to different routines and resized without breaking the reference. (Compare and contrast with realloc()'s behavior.) This could be particularly nice for string handling, a nasty area that C programmers struggle with.

I have tried to reproduce all relevant portions of the Classic/Carbon Memory Manager. Of course the Mac OS handled memory in a very different way back in the pre- OS X days, so there are a lot of architecture-specific routines like CheckAllHeaps() that are simply no-ops in MOSCH.

MOSCH.h should be self explanatory, there are tons of preprocessor switches you probably don't need to worry about. If you want documentation, I recommend Inside Macintosh: Memory at:

Download

Download MOSCH initial release

main.c and the Makefile produce a stupid test application that should at least indicate whether or not MOSCH is broken on your platform. I have compiled and run it under:

How to Use?

Just like you would the Mac OS Memory Manager! One difference: MOSCH uses the type MOSCH_Handle instead of Handle to avoid possible namespace collisions. If you want to just use the latter, or if you are porting Mac code, you can do like I did in the test app: define Handle as MOSCH_Handle.

Final Notes

  1. The 'resource' bit is honored but irrelevant. If you find a use for it, bless your heart.
  2. If you actually use this code, let me know.
  3. Suggestions and job offers are always warmly received.
  4. This thing has gobs of diagnostic code. Might help you track down a leak.
  5. MOSCH is fast! It's faster than I expected. Even on my putzy beige G3.
  6. No the code isn't commented. It was a two-day project, what can I say?

Home

Valid XHTML 1.0!