digitalmars.D.learn - Thread-local copy of data structure
- Marek Janukowicz (27/27) Jul 30 2013 I have quite complicated data structure (class-based) and I need a copy ...
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (8/18) Jul 30 2013 Fine: That is a requirement of your program. Another program may have
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
Jul 30 2013
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 atask, ordo 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 clonesI doubt it. Ali
Jul 30 2013