Object pool

from Wikipedia, the free encyclopedia

The object pool (Engl. Object pool pattern ) is in the software development employed design patterns , specifically a generation pattern . It is used to keep objects after their initial creation (in the object pool), if this makes more sense than creating them anew each time they are used. This applies above all to objects that are required and are complex to create . The objects are then stored in the object pool and made available again if required.

Example "library" for the creation pattern "object pool" of software development.

advantages

The reuse of object instances that have already been created potentially reduces the effort (time / computing power) for creating objects.

disadvantage

The reuse of already used objects increases the complexity of the program.

use

The object pool design pattern is often used, especially in the area of ​​thread pooling and connection pooling (e.g. database connections), there is often high potential for performance gains, since creating a thread and establishing a connection to a database management system are relatively 'time-consuming' . However, this is not the case for all object types ; especially with less complex objects , creating new objects is 'cheaper' than complex pooling mechanisms in current runtime environments .

example

A library can serve as an example of an object pool. A customer (client) borrows a book (object) from the library (object pool). After reading it, he returns the book to the library. This makes it available to other customers. The book does not have to be reprinted for each reading.

Delimitation of object pool to cache

An object pool saves the objects without a status, which means that they are in their initial status each time they are retrieved. With caching, on the other hand, the objects are saved including their status.

Web links

Individual evidence

  1. Joachim Goll, Manfred Dausmann: Architecture and Design Patterns of Software Technology . 4th edition. Springer Vieweg Verlag, Wiesbaden 2013, ISBN 978-3-8348-2432-5 , p. 78 .
  2. ^ Karl Eilebrecht, Gernot Starke: Patterns compact . 4th edition. Springer Vieweg Verlag, Berlin 2013, ISBN 978-3-642-34717-7 , p. 44 .
  3. ^ Karl Eilebrecht, Gernot Starke: Patterns compact . 4th edition. Springer Vieweg Verlag, Berlin 2013, ISBN 978-3-642-34717-7 , p. 44-45 .