For an MP for class, I needed a data structure. I thought to myself, well, how would it be done at Apple? CoreFoundation. So I dug in and really tried to understand the CoreFoundation framework, and then implemented by own mini-version with many of the same paradigms. The system I came up with was the MPRuntime.
Here’s how it’s described on the MPRuntime page and in the header:
The MPRuntime API provides a set of opaque data types written in procedural C. The types are meant to make creating collections (such as lists and queues) as well as your own types much easier. The runtime presents a memory model that aids in preventing leakage, and takes after the paradigms of Apple’s CoreFoundation framework.
It should be noted that as of right now, the only opaque types implemented in the runtime include the runtime base (allocators, runtime instances), in addition to a strong array type and a number type for dealing with numbers. As more types become available, read their individual descriptions for usage.
Memory management with MPRuntime is done using reference counting. For every function that returns an object that has “Create” in the name, the object returned should be sent to MPRelease when you are done with the object. Similarly, if you want to keep an object around, you can call MPRetain to increase the retain count by one. You can read more about this at the following URL: http://en.wikipedia.org/wiki/Reference_counting.
Go ahead, download it and give it a try! See how easy data structures in C can really be.
0 Responses to “The MPRuntime”