Passing large or complex data structures to threads
Simen Kjaeraas
simen.kjaras at gmail.com
Sun May 26 05:31:21 PDT 2013
On Sun, 26 May 2013 14:06:39 +0200, Joseph Rushton Wakeling
<joseph.wakeling at webdrake.net> wrote:
> On 05/24/2013 04:39 PM, Simen Kjaeraas wrote:
>> First, *is* it read-only? If so, store it as immutable and enjoy free
>> sharing. If not, how and why not?
>
> I can confess that it's as simple as feeling extremely uncomfortable
> dealing
> with immutable where it relates to any kind of complex data structure.
>
> I mean, for that double array structure I'd have to do something like,
>
> Tuple!(size_t, size_t)[][] dataCopy;
>
> foreach(x; data) {
> Tuple!(size_t, size_t)[] xCopy;
> foreach(y; x) {
> immutable(Tuple!(size_t, size_t)) yCopy = y.idup;
> xCopy ~= cast(Tuple!(size_t, size_t)) yCopy;
> }
> immutable xImm = assumeUnique(xCopy);
> dataCopy ~= cast(Tuple!(size_t, size_t)[]) xImm;
> }
>
> immutable dataImm = assumeUnique(dataCopy);
>
> ... no? Which feels like a lot of hassle compared to just being able to
> pass
> each thread the information to independently load the required data.
>
> I'd be delighted to discover I'm wrong about the hassle of converting
> the data
> to immutable -- I don't think I understand how to use it at all well, bad
> experiences in the past have meant that I've tended to avoid it.
That looks very complex for what it purports to do.
I understand data is the original data before sharing?
If so, will that a
--
Simen
More information about the Digitalmars-d-learn
mailing list