Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #612

Re: Design for shared data

From ittium <ittium@gmail.com>
Newsgroups comp.lang.c++, comp.programming.threads
Subject Re: Design for shared data
Date 2011-09-25 20:23 +0530
Organization A noiseless patient Spider
Message-ID <j5nf9f$mac$1@dont-email.me> (permalink)
References <j5miqi$mu6$1@dont-email.me> <j5mpve$shl$1@speranza.aioe.org> <4e7f294f$0$6627$9b4e6d93@newsspool2.arcor-online.net>

Cross-posted to 2 groups.

Show all headers | View raw


On 25-09-2011 PM 06:44, Marcel Müller wrote:
> 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.
>
Assuming that dependencies are mutable and so are always passed by 
reference, dependency injection will blow up the memory footprint, if 
you assume that most of the class will have large number of dependencies.

 From the discussion here and some googling, it appears DI with factory 
pattern seems to me as a good idea for average cases. I favor factory 
pattern so that dependency instance searching can be centralized.

Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Design for shared data ittium <ittium@gmail.com> - 2011-09-25 12:17 +0530
  Re: Design for shared data Qi <no@no.com> - 2011-09-25 16:45 +0800
    Re: Design for shared data Marcel Müller <news.5.maazl@spamgourmet.org> - 2011-09-25 15:14 +0200
      Re: Design for shared data ittium <ittium@gmail.com> - 2011-09-25 20:23 +0530
  Re: Design for shared data Paavo Helde <myfirstname@osa.pri.ee> - 2011-09-25 06:05 -0500

csiph-web