[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: computer-go: unmake move?
> See my previous post, I suggesting throwing away the unmake routine!
>
> Don
I agree. Writing an "undo" logic is extremely difficult and tricky, and
probably doesn't offer a great enough performance increase to justify the
additional complexity.
In my Go program, I have objects which use a copy-on-write scheme to avoid
excessive copying of data-structures. This works well when not too many
objects are effected by a single move and when instantiated objects are more
than a few bytes of memory. The cost of copying data-structures (especially
depth ones in non-contiguous in memory) vastly out weight the additional run
time cost of using this method. The addition run-time cost is one additional
level of in-directness to data structures (i.e.., another pointer traversal)
and the check if the data-structure is shared for all write operations on an
object. I have partition all my Go objects appropriately so that a single
move doesn't effect everything. In addition, most objects' data-structures
are at least a few hundred bytes. This idea isn't new. Most of my objects
derived from an base object called RCObject which is described in Effective
C++ and More Effective C++ both by Scott Meyers.
Here's a sampling of my code:
BitMap a;
a.Set(1,1);
BitMap b= a, c = a; // only pointers are copied, all data-structures are
shared
b.Set(1,2); // the shared data-structure is copied, then this "new"
copy is modified
a.Print(); // contains (1,1)
b.Print(); // contains (1,1) & (1,2)
c.Print(); // contains (1,1) - shares the same data-structure as object
a.
I hope this is of some benefit to others.
- Phil