c++ - Minimal latency objects pooling technique in multithread application -


  1. in application have 30 types of objects created repeatedly.
  2. some of them have long life (hours) have short (milliseconds).
  3. objects created in 1 thread , destroyed in another.

does have clue pooling technique in sense of minimal creation/destruction latency, low lock contention , reasonable memory utilization?

append 1.

1.1. object pool/memory allocations 1 type not related type (see 1.3 exception)

1.2. memory allocation performed 1 type (class) @ time, several objects @ time.

1.3. if type aggregates type using pointer (for reason) these types allocated in 1 continuous piece of memory.

append 2.

2.1. using collection access serialization per type known worse new/delete.

2.2. application used on different platforms/compilers , cannot use compiler/platform specific tricks.

append 3.

it becomes obvious fastest (with lowest latency) implementation should organize object pooling star-like factories network. central factory global other thread specific factories. regular object provision/recycling more effective in thread specific factory while central factory used object balancing between threads.

3.1. effective way organize communications between central factory , thread specific factories?

i assume have profile , measured code after doing creation , verified create/destroy causing issue. else should first.

if still want object pooling, first step, should ensure objects stateless coz, prerequisite reusing object. should ensure members of object , object has no issue being used different threads other 1 created it. (com sta objects / window handles etc)

if use windows , com, 1 way use system provided pooling write free threaded objects , enable object pooling, make com+ run time (earlier known mts) you. if use other platform java perhaps use application servers define interfaces objects should implement , com+ server pooling you.

or roll own code. should try find if there pattern , if yes use instead of follows below

if need roll own code, create dynamically growable collection tracks objects created. use vector preferrably collection since adding collection , easy traverse searching free object. (assuming not delete objects in pool). change collection type according delete policies (vector of pointers/references objects if using c++ delete , recreate object @ same location)

each object should tracked using flag can read in volatile manner , changed using interlock function mark being used/ not used.

if objects used, need create new object , add collection. before adding, can acquire lock (critical section), mark new object being used , exit lock.

measure , proceed - if implemented above collection class create different collections different object types reduce lock contention threads different work.

finally implement overloaded class factory interface can create kinds of pooled objects , knows collection holds class

you optimize on design there.

hope helps.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -