Re: Design for shared data
On 25.09.11 10.45, Qi wrote:
On 2011-9-25 14:47, ittium wrote:
Group,
I have a design a multi-threaded system that uses good amount of shared
data. This data is needed in multiple classes/functions. I have three
designs for it.
1. Keep the data global, so that it can be accessed any where
2. Wrap the data in singleton class and use it wherever needed by
getInstance static method.
3. Pass the data by constant reference where ever needed. In this case
if function is part of some function hierarchy then data will have to be
passed from topmost function to the function where it is used.
Singletons are evil
http://blogs.msdn.com/b/scottdensmore/archive/2004/05/25/140827.aspx
Well, the alternative, dependency injection, becomes evil to, if it has
to be applied multiple times to the same classes for a dozen different
global services. It even might blow up the memory footprint of your
application it DI has to be applied to many objects, unless you pass the
reference to the global singleton as template parameter. So it depends.
And they are more evil in multiple thread.
This makes no difference at all. You have to take care of thread safety
anyway.
Marcel