July 30, 2013 Thread-local copy of data structure | ||||
---|---|---|---|---|
| ||||
I have quite complicated data structure (class-based) and I need a copy of it in a Task (std.parallelism). There is a simplification of data structure and my program:
class A {
B [] arr;
}
class B {
C c;
}
class C {
A a;
}
void main () {
a = new A();
... // Further initialization of data structure
auto taskObject = new TaskObject( a );
auto t = task(taskObject);
taskPool.put( t );
}
Now "a" in my task is the same as "a" in main thread and I'd like a local copy - to be precise I need to make changes to a in the task, but they should not affect main copy. Is it possible to somehow create copy automatically when creating a task, or do I need to create it myself? If the latter - is there anything in std lib that helps with creation of deep clones or an I completely on my own?
--
Marek Janukowicz
|
July 31, 2013 Re: Thread-local copy of data structure | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marek Janukowicz | On 07/30/2013 01:15 PM, Marek Janukowicz wrote: > class A { > B [] arr; > } > Now "a" in my task is the same as "a" in main thread and I'd like a local > copy - to be precise I need to make changes to a in the task, but they > should not affect main copy. Fine: That is a requirement of your program. Another program may have different requirements. > Is it possible to somehow create copy automatically when creating a task, or > do I need to create it myself? It is possible to write a general function that performs deep copying of members and others have implemented such functions. > If the latter - is there anything in std lib that helps with creation of > deep clones I doubt it. Ali |
Copyright © 1999-2021 by the D Language Foundation