Thread-local copy of data structure

Marek Janukowicz marek at janukowicz.net
Tue Jul 30 13:15:26 PDT 2013


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


More information about the Digitalmars-d-learn mailing list