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

Spring - Request scoped bean from object pool

I have an object pool of resources: public interface PooledResource { ... } @Component public class ResourcePool { public PooledResource take() { ... } public void give(final PooledResource…
Dave Jeod
  • 37
  • 5
1
vote
0 answers

In pooling, is reusing a recently "recycled" object better than one that has been inactive for longer?

Consider the following scenario: An object pool is created with a thousand (1000) objects of a moderate instantiation and initialization weight. Of those, 800 are used in the application for a while. Then, 200 are no longer used, so they are…
CosmicGiant
  • 6,275
  • 5
  • 43
  • 58
1
vote
3 answers

Generic object pool

Is it possible to create a generic object pool that creates new objects inside it? Plus it would be nice if this object creation could receive parameters. public interface IPoolable { void Dispose(); } public class…
MathiasDG
  • 81
  • 1
  • 9
1
vote
1 answer

Cocos2d-x Object Pooling

I created object pool as the following. void Arrow::CreatePools( cocos2d::Layer *layer ) { Sprite * sprite; int i; //--CREATE ENEMY OBJECT POOL--// enemyPool = new Vector(MAX_ENEMY_NUMBER); enemyIndex = 0; for (i =…
Valar Morghulis
  • 916
  • 1
  • 9
  • 26
1
vote
1 answer

Return Object to pool

I am making infinity road game. I am using object pooling for roads and enemy objects. roads is working well but I have problem with enemy objects, I can add enemy from pool but I cant return back enemy objects to pool. public void CreateEnemy(…
Valar Morghulis
  • 916
  • 1
  • 9
  • 26
1
vote
0 answers

Object Pooling Bullet Spawn

I have a simple object pool in place for a gun I am using. However after an object has been set to inactive and is free for use again, when it gets used it shoots out in its old direction. I am not used to using pooling for such tasks so I'm not…
bSky
  • 187
  • 2
  • 12
1
vote
3 answers

Object pooling in Objective-C

Is there a nice way to do this in Objective-C, or do I have to write my own tedious logic? I'm creating and destroying a little of little state objects per frame in an iPhone game. It would be nice if I could just reuse objects from a pool.
1
vote
1 answer

Java - How handle JDBC connections inside your DAO

I have a DAO and I implement a connection pool. I instantiate the connection pool using a singleton to have only one instance. I call on the getConnection function to get my connection inside of my DAO. I do this for each method within the DAO? Is…
user3590149
  • 1,525
  • 7
  • 22
  • 25
1
vote
2 answers

One-off object pooling with Actor provider

I have an object with heavy initialization cost and memory footprint. Initialization time is human-noticeable but creation frequency is low. class HeavyClass { heavyInit() } My solution is to create a Provider actor that would have a single…
gsimard
  • 643
  • 8
  • 24
1
vote
1 answer

Object pooling: evil on desktop, recommended on mobile device. How this could be?

I used to read various blogs and recommendations that pooling normal Java objects (not objects like connections or the like) does not improve and may actually decrease the performance, being an anti-pattern. However this is much less common to hear…
Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
1
vote
1 answer

Is Javascript object pooling to avoid garbage collection worthwhile?

I am trying to build out a game kit for Javascript running in a browser. I have already run into the dreaded 100ms+ pauses that excessive garbage collection can cause. This tends to wreck the user experience. The remedy to this, as I have read it,…
Jim Noble
  • 492
  • 6
  • 12
1
vote
2 answers

Object pooling: howto

I need to implement a pool of Sessions that are returned by an external system, so that I can reuse them quickly as soon as one is needed (creating a Session takes a while). I've worked with datasource to create a pool of database connections (DBCP…
EugeneP
  • 11,783
  • 32
  • 96
  • 142
1
vote
1 answer

Universal object pool

I see the benefit of using object pooling, and I also want to combine it with Vectors. But, reading about Vectors, I see that they can only be defined at compile time, meaning a separate pooler class for each of the pooled classes is required. On…
Vesper
  • 18,599
  • 6
  • 39
  • 61
1
vote
1 answer

Android Implement object pool in Andengine for different type of Entities

I am developing a game in AndEngine for Android. In my game, I have to create different types of Tiles (AnimatedSprite) after every second. I have done that. But I am feeling jerks and lags in my game. I think it is due to the allocation and…
Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
1
vote
0 answers

Resources for implementing object pooling in prototypical not classical JavaScript

quick question (with slightly laborious build up).... Both Douglas Crockford and Stoyan Stefanov in their JavaScript books strongly encourage staying clear of Classical (class based) paradigms when implementing JavaScript projects, and exploiting…
James Cat
  • 432
  • 2
  • 12