Am Sonntag, 22. April 2007 09:11 schrieb Patrick Rutkowski: > I think Leo would be the best person to go to for an explanation, > especially if you plan to dramatically rework the code.
> >> This is where I start not to understand. Why reg_alloc + 7? Why > >> shift left > >> and right by 3? > > > > I'm not sure if it is actually doing anything that needs to be that > > complicated to code that way. It could be able to be written as: > > > > const int slot = (reg_alloc + 7) / 8; /* divide by eight for > > some reason and round up on remainder */ > > reg_alloc = slot * 8; /* reg_alloc is now evenly divisible by 8 */ Sure. It's just rounding up to the next multpile of 8. > > ... Now, slot is multiplied by sizeof(void*) later on, > > which may be why it's divided by eight in the first place. The rounding up happens to reduce the size of the free_list array. > > The n = slot + 1 I find a little odd, because the number is already > > rounded up, so it's rounding up and then adding an extra place of > > memory. This is for the extension of the free_list. > >> I do understand the purpose of the resizing code, but not how slot > >> relates to > >> it: > >> > >> if (slot >= interp->ctx_mem.n_free_slots) { Well, if slot is beyond the end of the list, it's resized. > > The *(void **) has been confusing me for a long time. The free list per size (i.e. one slot) is a linked list of pointers. > >> I'd like to find a simpler scheme, if it's possible. Otherwise, > >> I'd like to > >> figure out what's going on so we can at least explain it somehow. Why? This is all rather straight-forward and can be found in any memory allocator e.g. ins smallobjects. leo