Passing large or complex data structures to threads

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Fri May 24 06:26:21 PDT 2013


Hello all,

Are there any recommended strategies for passing large or complex data
structures (particularly reference types) to threads?

For the purpose of this discussion we can assume that it's read-only data, so if
we're talking about just an array (albeit perhaps a large one) I guess just
passing an .idup copy would be best.  However, the practical situation I have is
a data structure of the form,

	Tuple!(size_t, size_t)[][]

... which I _could_ .idup, but it's a little bit of a hassle to do so, so I'm
wondering if there are alternative ways or suggestions.

The actual way I found to "solve" this problem (for now) was that, since the
data in question is loaded from a file, I just got each thread to load the file
separately.  However, this runs into a different problem -- the function(s)
required to load and interpret the file may vary, and may require different
input, which requires manual rewriting of the thread function when it needs to
be changed (it's a tolerable but annoying solution).  I guess I could solve this
by passing the thread a delegate, or maybe employ mixins ... ?

Anyway, I thought I'd throw the question open in case others can suggest better
ideas!

Thanks & best wishes,

     -- Joe


More information about the Digitalmars-d-learn mailing list