Learning object pool

concept

In order to avoid creating a large number of (configuration) object destruction performance overhead (destruction) of the target tape

design

  • Target queue
    • During initialization, the queue length
    • The team, the team need to lock protection operation
    • Constructed object
      • Good structure when the object is initialized pool
      • All objects are not a good start construction, but in the process of acquiring the object's constructor (after construction will be saved for use in the queue)
  • Get Object
    • Providing an interface
  • The return of objects
    • It provides an interface display to return
    • C ++ RAII use characteristics (i.e. smart pointer destructor, call return operation), an implicit return
  • Object Manager
    • Responsible for building objects and destroying objects
    • Management status of each object
  • Get Status Interface
    • Providing an interface, the user can acquire various information about the state of the target pool

Precautions

  • Update object pool
    • When an object may require specific configuration parameters, run-time parameter is changed so as to update the target cell, the user needs to ensure the safety thread to access the object during the update operation, the following is an embodiment (updating the entire object pooling Example):
      • The use of smart pointers holding the object pool instance, read-write locks and protect its access operation
        • Using smart pointers can provide thread-safe access to the original object instance pool after the update operation occurs
        • The assignment is executed only when using smart pointers smart pointer update operations (write-lock, blocking) can occur
      • The user constructs a new object instance pool if necessary, replace the original object pool instance after successful initialization, write-lock

cpp object pool project

https://github.com/chenguang9239/generic_object_pool.git

Guess you like

Origin www.cnblogs.com/wangzhiyi/p/11565051.html