Reader small image

You're reading from  Game Development Patterns with Unity 2021 - Second Edition

Product typeBook
Published inJul 2021
Reading LevelBeginner
PublisherPackt
ISBN-139781800200814
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
David Baron
David Baron
author image
David Baron

David Baron is a game developer with over 15 years of experience in the industry. He has worked for some well-known AAA, mobile, and indie game studios in Montreal, Canada. His skill set includes programming, design, and 3D art. As a programmer, he has worked on various games for various platforms, including virtual reality, mobile, and consoles.
Read more about David Baron

Right arrow

Understanding the Object Pool pattern

The core concept of this pattern is simple—a pool in the form of a container holds a collection of initialized objects in memory. Clients can request an Object Pool for an object instance of a specific type; if one is available, it will be removed from the pool and given to the client. If there are not enough pooled instances at a given time, new ones will be dynamically created.

Objects that exit the pool will attempt to return to it once they are not used anymore by the client. If the Object Pool has no more space, it will destroy instances of objects that attempt to return. Therefore, the pool constantly gets refilled, can only be temporarily drained, but never overflows. Hence, its memory usage is consistent.

The following diagram illustrates the back and forth between a client and an Object Pool:

Figure 8.1 – Unified Modeling Language (UML) diagram of the Object Pool pattern

In the diagram, we can see that the Object...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Game Development Patterns with Unity 2021 - Second Edition
Published in: Jul 2021Publisher: PacktISBN-13: 9781800200814

Author (1)

author image
David Baron

David Baron is a game developer with over 15 years of experience in the industry. He has worked for some well-known AAA, mobile, and indie game studios in Montreal, Canada. His skill set includes programming, design, and 3D art. As a programmer, he has worked on various games for various platforms, including virtual reality, mobile, and consoles.
Read more about David Baron