delphi - How to increase the reference count of subarrays when the refcount of the holding array increases? -
delphi - How to increase the reference count of subarrays when the refcount of the holding array increases? -
i have cowarray works ok, want expand number of dimensions so:
type tcowarray2<t> = record private type titem = record fitems: tarray<t>; fstart, ffinish: nativeint; end; private fitems: array of titem; private methods public .... end;
the array splits items in blocks. every sub array has e.g. 100 items , mean array has many items needed. outside 1 dimensional array presented, internally info of type t
stored in subarray.
this way can have re-create of write little copying going on when single item changes. instead of cloning 20,000 items, 100 items clones plus mean array 200 items, i.e. 300 items 99% reduction of effort , storage.
the problem need maintain track of changes in reference count of main array , propagate sub-arrays.
something like:
procedure tcowarray<t>.somemember.addref; var item: titem; begin inherited; item in fitems item.increaserefcount; end;
obviously performance reasons utilize plain loop
how do this? thinking of adding custom tinterfaced object, i'm not sure how create work.
this appears sec in multi-dimensional series of questions.
the first question in series, outer dimension, here: why compiler insist function inline when it's not? although question title concerned error message, became question concerning implementation of copy-on-write array. one-dimensional version of question.
now move on question. two-dimensional version. solve same way first question. because exact same issue. 1 time can solve one-dimensional array, same solution works n dimensional array.
when need modify element of array, phone call setlength
on internal array. gives unique outer array. copying happens here, copies references inner sub-arrays.
then identify inner sub-array need operate on. when you've done that, phone call setlength
1 time again create inner sub-array unique. modify value.
it not matter how many dimensions add. reply same. i'm hoping question can terminate series! ;-)
arrays delphi delphi-xe2 reference-counting copy-on-write
Comments
Post a Comment