Questions tagged [object-pooling]

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand.

The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When the client has finished, it returns the object to the pool rather than destroying it; this can be done manually or automatically.

Object pools are primarily used for performance: in some circumstances, object pools significantly improve performance. Object pools complicate object lifetime, as objects obtained from and return to a pool are not actually created or destroyed at this time, and thus require care in implementation.

Object pooling can offer a significant performance boost in situations where the cost of initializing a class instance is high and the rate of instantiation and destruction of a class is high – in this case objects can frequently be reused, and each reuse saves a significant amount of time. Object pooling requires resources – memory and possibly other resources, such as network sockets, and thus it is preferable that the number of instances in use at any one time is low, but this is not required.

http://en.wikipedia.org/wiki/Object_pool_pattern

171 questions
1
vote
1 answer

MinEvictableIdleTimeMillis setting not working as expected

I have this pool of objects (using org.apache.commons.pool2), from which I borrow (or create) one. The maximum idle size I have set is 3 ( with a max size of 5). This was set with the understanding that if there are idle objects more than 3, those…
user1583803
  • 424
  • 2
  • 6
  • 16
1
vote
0 answers

How do I make my object pool a singleton?

I have implemented this object pool (using org.apache.commons.pool2) to manage a pool of objects, which is defined in the parent class, say A There are a few child classes, for eg: B and C which extend A - and makes use of this object pool. The…
Chillax
  • 4,418
  • 21
  • 56
  • 91
1
vote
2 answers

Unity: Get the position of the last cloned instantiated object

I'm trying to create an infinite ground for Android using Unity. Trying to use object pooling to achieve the ground repeating but is proving a bit tricky. I can get my ground to Instantiate and create the clones along x axis. What I am trying to…
1
vote
5 answers

GameObject.Find() in Unity 3D

This is a C# method I found in a Unity3D tutorial: Public List pieces = new List(); // list of pieces in the pool public Piece GetPiece(PieceType pt, int visualIndex) { Piece p = pieces.Find(x => x.type == pt && x.visualIndex ==…
Achie1
  • 195
  • 2
  • 13
1
vote
1 answer

How can adapt my object pooler to reset for each new scene that I load?

After updating the game according to the specifications given in the answer I now get the following error message: Assets\ObjectPooler.cs(79,41): error CS0103: The name 'pool' does not exist in the current context. I understand why it doesn't work…
1
vote
2 answers

Why don't people use object pooling in Xamarin?

I'm new to mobile development, and by extension, Xamarin. One thing I've always noticed is that any time a page is loaded, people always request to make a new page() as opposed to have a pool or set list of pages they can access. Won't this cause…
TRMN8R
  • 33
  • 5
1
vote
6 answers

Fastest method to find a complex type in a list (Vector, Array, Dictionary, whatever is faster)

Hail, Stack! I need to know the best method to find an item inside a list (Vector, Array, Dictionary, whatever is faster) of complex type (extensions of Objects and Sprites). I've used "Needle in Haystack" method, but it seems that it isn't fast…
NemoStein
  • 2,088
  • 2
  • 22
  • 36
1
vote
0 answers

recursively calling method (for object reuse purpose)

Possible Duplicate: recursively calling method (for object reuse purpose) i have a rather large class which contains plenty of fields (10+), a huge array (100kb) and some unmanaged resouces which process long running task and i want to reuse it…
TakeMeAsAGuest
  • 957
  • 6
  • 11
1
vote
3 answers

Questions about ObjectPooling

I am currently working on a simple UDP server for a game. I have already implemented multithreading with the help of a ThreadPoolExecutor. When reading about how to maximize performance I stumbled across ObjectPooling. After some reading I have been…
Maxwell
  • 133
  • 1
  • 7
1
vote
2 answers

Gaps in Endless Runner "Treadmill" with Object Pooling

I am working on a 3D endless runner game, where the player is stationary, and the background/obstacles move around them. I am using object pooling. The background is made up of multiple variations of a large "City Block" object, which consists of a…
A.Crane
  • 435
  • 1
  • 3
  • 12
1
vote
1 answer

Object Pooling Design Pattern Close All Idle Connection

This is a question about object pooling design pattern with MySql Connection. The intention of implementing this design pattern is to reuse the same connection/object when more than one instances needs to be created. Below code is a class of object…
J.Smith
  • 11
  • 1
1
vote
2 answers

Arbitrary number of parameter assignment with template class

I would like to implement a simple template ObjectPool kind of class. It has a fixed size vector as a member variable, which elements' are default initialized upon creation. That's done already and works fine. The question is what is the best way to…
Avi
  • 1,066
  • 1
  • 15
  • 37
1
vote
1 answer

NetworkStream Pooling

I have a multi-threaded application which communicates with a server over a TCP connection. The application would be deployed as a windows service. The way it has been implemeted is, there is Controller which creates Communicator objects, assigns…
Danish Khan
  • 1,893
  • 5
  • 22
  • 35
1
vote
0 answers

Why is the release() function in this JavaScript object pool implementation allocating so much memory, or indeed any?

I'm working on a number of games (here's one: https://arcade.ly/games/asteroids/) and, to try to keep the framerate a little more reliable on some browsers/devices, I'm using object pools for frequently created objects, like particles. I create…
1
vote
2 answers

How to prevent same object from being picked from array twice in a row

I am having a bit of a problem figuring out how to randomly get an object out of a list that wasn't picked on the last update of a script. When this randomly instantiated object is spawned and reaches a certain y value, it will set itself to…