Saturday, January 2, 2010

Some Things I Would Do if I were Really Writing This

This blog is about learning the pieces and parts of ARM Assembly language. If I were really writing a heap manager, I would do the following:

I'm assuming this design is for a heap manager that stores objects of various sizes. That's why I include the size of the value (in bytes) along with it's position in the heap. If this were a string pool, I might just include the position in the heap and use a delimiter character. I believe this is how actual string pools are organized.

If it were a string pool, it might be worth while to include, instead of size, other information about the string saved. For instance, if you match a string with an existing string (as Java does) in the pool, it could speed things up to know the first character or first ten characters. That way, when comparing a string to all the strings in the pool, you would only have to read a few close possible matches from the heap.

The design I chose only used 8 bits to address locations in the heap. The design has another 16 bits free for this, bringing us to a total of 16777216 possible addressable bytes. That's one fourth the size of the addressable memory in an ARM chip.

Likewise, I only implemented values of size 1-4. This design can accommodate values of 1 to 256 with little tinkering. Again, this would be good for objects of varying size, but bad for strings.

So, if I were writing a heap manager, I would start by figuring out what kind of values would be living on the heap. The size of the Heap Manager portion of memory could be customized.

I'd start with a test section of code. This should include more than just the vanilla cases I used in this version. It would include the edge cases - the situation where you fill the heap completely or fill the manager completely. The cases where you would end up reading or writing outside the heap area.

And I think I'd design it in C, at least as a first version. For managing memory, I don't think a higher level language - like C# or Java - would be a good idea. It's one of the few things that you need C or assembly for.

No comments:

Post a Comment