Sunday, November 14, 2010

The means to the end is also important

I have been low on the radar because I have been working hard on the code instead of updating the blog but mostly because I didn't have anything to show.

I now do have a another snapshot of my code to show. While this is in no way Screens, it does preview the object storage with some example components.

I now support singleton components (components with only a single instance) and improved the overall design of how components are used. I also made it simpler to write a component as you can see in the attached code.

You can find the code here:

About the multi-level assocation hierarchy, I removed that since not only did I find its use limited, but it was too complex for me to handle or explain to others, so I axed it. It was basically to allow each instance to have child instances while still being attached to the same object.

A few notes:

1. Allocation in chunks
It allocates objects per components in single allocations of 256 objects per component (apart from singleton components). It then re-uses allocations of the components. This reduces the problem of memory fragmentation.

2. Object limit
I currently have a maximum limit of about 65,000 objects. This is because I have an overhead of 32bits per objects which contains two 16bit references. However this implementation limit is encapsulated in CoreObject, so in the future this could be changed without an overhall on all the code.

3. Multi-instance support
You can attach multiple instances of the same component to a single object. This is how CoreNotify works where it just attaches each new notification to the same object and then uses CoreObjectCast to retrieve the next notification for message broadcast.

4. Simple component use
I have reduced the component overhead to a single public function that calls CoreObjectInit, a single typedef to define the object type and variable declaration in the header file of the component. The object can be any type, it can be an integer, character pointer, structure, union or anything fixed that C supports (it does not support non fixed character arrays since all objects must be of the same size per component).