5.08.2011

Iterators

Well, since my rendering concept involves a bunch of lists, I had get them into my program somehow. If it'd be C++, it could simply use my existing codebase. Not so with leJOS - there doesn't seem to be any linked list that's truely one. They are using arrays all the time but no linkage. So I asked myself: try to port your own class or invent a new one? Well, it's easy to port my favorised one (I already did, a matter of seconds), but thinking about the the memory limitations and that only have a maximum of 32kb available with in leJOS, it could be worth taking a look at pre-allocated data for storing data. The task I give leJOS is quite memory-demanding. You need to store 4 ints for a rectangle, 2 for a point and additional references and temporary rectangle data. I can see where this could cause trouble with many display elements. So that's a situation where I finally encountered a problem that's more smart to solve with iterators! Iterators aren't specialised, they use an underlying interface and redirect to a certain function. I could've designed it with my linked list, wasting memory as I go and forcing the garbage collectors to take his time for cleaning up once in a while. This wouldn't happen in a C program, but I don't have such things at hand. So to avoid later trouble with what memory structures to use, I consider writing my own set of iterator rules and underlying classes. It always ends like this, eh? Anyway, if I can't avoid inheritance or interfaces in this case, I should use it wisely. Inheritance is one of these things I simply dislike. Interfaces on the other hand are extremely handy for writing more generic stuff. Whatever, this is a bit annoying. Not just a bit, it's stupid. Pah...

No comments: