Computer Science Canada Oh OOP how I love you. |
Author: | mirhagk [ Sun Mar 06, 2011 4:34 pm ] |
Post subject: | Oh OOP how I love you. |
I wrote a program the other day, and thanks to polymorphism I saved like 50% of the memory the program used (which is measured in MB) and made the most critical algorithm twice as fast. How did this happen? Well it was a quad node tree class, and the end nodes were the parent class, and the non-end nodes (branches I guess) were inherited from this. this meant that the end nodes did not have a wasted pointer to it's non-existent children, and none of the algorithms needed an extra if statement to see if it was the end node or not, this was simply implied. I could have even saved more space and such if I removed the actual data from all but the end nodes, but I opted to not so I can implement a LOD system (where it only gets from the first couple nodes, insteading of going deep in the tree.) However I am still debating over this, since say the max level is 20 and the LOD I want is 10, it would have to check to see if it's the right level and decrement it each time, meaning that there was no optimizations, and probably even some loss of speed. The only time that the LOD would be handy is if I really only want the 10th level. Anyways my point is that OOP doesn't always mean better organization for less speed, sometimes it can actually make it be faster |