I took the classic callback approach and it seems to work very well. I also added an incrementing value to see how many values are alreay filled and so on. Now I have to memoization arrays: one based on preallocated objects (aka simple array with bool flags) and one based on a dynamically allocated objects. The second variant uses the stored pointers as status flags. Combined with returning a pointer to a constant memory, I can use nice read-only functionality while keeping it open for really big objects to store. And again, in this case it's again rather "the C way", only if C had references... That's probably also why I prefer to code in C++ - too many nice extras you don't get in classic C code. However, since this is solved, I need to get my third variant running. It'll base on the idea I'm carrying around since I began with implementing memoization. And I now sorted out how merge it into a better systems with less frequent "chunk" allocation depending on how the binary pattern of your index changes from call to call. One variant gives less allocation with no frequent changes on the lower bits, the other one works similarly but with higher bits. So in the end it depends on what you'll want to get from it. I'll stick with the first variant, since I think this is more usual than the other version. I thought about using even more binary splits, but where's the point then? It'd be just more bit masking with no real use except in combination with a single flag indicating whether a chunk it fully completed, thus marking his child chunks as complete and speeding up such accesses. Hm, not a bad idea! But kind of lame cause no matter how hard you try, it's always faster to simply make two checks with only two splits instead of n splits and even more checks. Simplicity is the key here, don't make anything too fancy - you'll regret it if it comes to performance and compatibility.

No comments: