[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory management



Keith Lucas wrote:

> >Darn, I have one right into my face (the list of window in my prototype
> >library is a circular list in Z-order with the parent pointing at the
> >one on top)... This is one of the case where pure refcounting easily
> >comes apart, and believe me, it occurs more often than I'd like it to!
> >:-)
> 
> Well, not to be disrespectful or anything, but either your code or your
> constraints are broken... unless you really do have windows which bend in
> the Z direction. A window which is on top of another cannot also be under it
> if they are flat in Z. There is a root window, which has no window under it
> pointing at it and there is a top-most window which cannot point to anything
> since nothing is obscuring it. The data structure isn't modelling the
> problem.

This is simple optimization. Z-order, in the purest sense, is a list,
from nearest to fartest. But raising a window would mean updating many
pointers, moving the end of the list at the top, grafting what was the
top at the end (meaning finding the end, which means walking the list
for a simple singly linked list) and finally updating the pointer to the
list in the parent window.

Instead, I just change the pointer in the parent window to the next
window and everything is fine (except refcounting). MFC does it this way
I think, Turbo Vision (eeks!) used to do it this way, and probably
others.

-- 
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi