2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Object Pool
|
|
|
|
folder: object-pool
|
2015-08-15 18:03:05 +02:00
|
|
|
permalink: /patterns/object-pool/
|
2015-08-20 21:40:07 +02:00
|
|
|
categories: Creational
|
2015-12-28 15:52:44 +02:00
|
|
|
tags:
|
2019-12-13 21:09:28 +02:00
|
|
|
- Game programming
|
2015-12-28 16:07:43 +02:00
|
|
|
- Performance
|
2015-08-13 23:54:40 +02:00
|
|
|
---
|
|
|
|
|
2016-01-03 21:14:30 +01:00
|
|
|
## Intent
|
|
|
|
When objects are expensive to create and they are needed only for
|
2015-08-13 23:54:40 +02:00
|
|
|
short periods of time it is advantageous to utilize the Object Pool pattern.
|
|
|
|
The Object Pool provides a cache for instantiated objects tracking which ones
|
|
|
|
are in use and which are available.
|
|
|
|
|
2019-12-07 20:01:13 +02:00
|
|
|
## Class diagram
|
2015-08-13 23:54:40 +02:00
|
|
|

|
|
|
|
|
2016-01-03 21:14:30 +01:00
|
|
|
## Applicability
|
|
|
|
Use the Object Pool pattern when
|
2015-08-13 23:54:40 +02:00
|
|
|
|
2019-12-13 21:09:28 +02:00
|
|
|
* The objects are expensive to create (allocation cost)
|
|
|
|
* You need a large number of short-lived objects (memory fragmentation)
|