object-pooling

Unity: Need to reset a pooled object on return to pool. Perhaps using ScriptableObject?

北城余情 提交于 2019-12-07 23:27:39
问题 I have recently been trying out object pooling in unity to speed up the instantiation of several game objects at once. However, since these are fairly complex objects I need to reset them when they go back in the pool. I read that using ScriptableObject might be a good way to store the default values for an easy reset. But in order to do that I need to load a fresh ScriptableObject at runtime to store the actual values of the object. So in pseudocode, i'd have a class with public

Unity: Need to reset a pooled object on return to pool. Perhaps using ScriptableObject?

对着背影说爱祢 提交于 2019-12-06 09:18:11
I have recently been trying out object pooling in unity to speed up the instantiation of several game objects at once. However, since these are fairly complex objects I need to reset them when they go back in the pool. I read that using ScriptableObject might be a good way to store the default values for an easy reset. But in order to do that I need to load a fresh ScriptableObject at runtime to store the actual values of the object. So in pseudocode, i'd have a class with public MyScriptableData data and public MyScriptableData defaults 1) create new pooled object with default

Object pool vs. dynamic allocation

拥有回忆 提交于 2019-12-03 19:07:27
问题 When should one prefer object pool over dynamically allocated objects? I need to create and destroy thousands of objects per second. Is it by itself enough to decide in favor of object pool? Thanks. 回答1: Yes, this is enough to decide in favor of object pool. Quoting Boost documentation When should I use Pool? Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation above, where many objects may be dropped out of memory

Is there an open source thread safe C++ object pool implementation?

99封情书 提交于 2019-12-03 14:35:09
I need to create a pool of socket connections which will be served to multiple worker threads. Is there a thread safe object pool implementation with functionality similar to Apache Commons' GenericObjectPool ? Check out boost . flyweight . I usually use TBB to implement thread-safe scalable pools. template <typename T> class object_pool { std::shared_ptr<tbb::concurrent_bounded_queue<std::shared_ptr<T>>> pool_; public: object_pool() : pool_(new tbb::concurrent_bounded_queue<std::shared_ptr<T>>()){} // Create overloads with different amount of templated parameters. std::shared_ptr<T> create()

Is there a general-purpose object pool for .NET?

对着背影说爱祢 提交于 2019-12-03 05:13:53
问题 I have a class that is expensive to construct, in terms of time and memory. I'd like to maintain a pool of these things and dispense them out on demand to multiple threads in the same process. Is there a general-purpose object pool that is already tested and proven? (I don't want COM+ pooling.) 回答1: No Cheeso, there is no general object pool like this. But it is a good idea. I think this would be pretty simple to develop. The key thing is making it work well in a threaded environment. I think

Is there a general-purpose object pool for .NET?

你。 提交于 2019-12-02 17:37:36
I have a class that is expensive to construct, in terms of time and memory. I'd like to maintain a pool of these things and dispense them out on demand to multiple threads in the same process. Is there a general-purpose object pool that is already tested and proven? (I don't want COM+ pooling.) No Cheeso, there is no general object pool like this. But it is a good idea. I think this would be pretty simple to develop. The key thing is making it work well in a threaded environment. I think this is an interesting design problem. For example, if this needs to to scale on sever class hardware -and-

Generic InternPool<T> in Java?

浪子不回头ぞ 提交于 2019-12-01 03:49:01
How would I write a generic InternPool<T> in Java? Does it need a Internable interface? String in Java has interning capabilities; I want to intern classes like BigDecimal and Account . Something like this: public class InternPool<T> { private WeakHashMap<T, WeakReference<T>> pool = new WeakHashMap<T, WeakReference<T>>(); public synchronized T intern(T object) { T res = null; // (The loop is needed to deal with race // conditions where the GC runs while we are // accessing the 'pool' map or the 'ref' object.) do { WeakReference<T> ref = pool.get(object); if (ref == null) { ref = new

Object pool vs. dynamic allocation

此生再无相见时 提交于 2019-11-30 05:08:36
When should one prefer object pool over dynamically allocated objects? I need to create and destroy thousands of objects per second. Is it by itself enough to decide in favor of object pool? Thanks. Yes, this is enough to decide in favor of object pool. Quoting Boost documentation When should I use Pool? Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation above, where many objects may be dropped out of memory. See Boost Pool library The expected cost of destructing the object, deallocation, allocation and

Does this basic Java object pool work?

耗尽温柔 提交于 2019-11-28 23:48:37
Does the following basic object pool work? I have a more sophisticated one based on the same idea (i.e. maintaining both a Semaphore and a BlockingQueue). My question is - do I need both Semaphore and BlockingQueue? Am I right that I don't need to do any synchronisation? import java.util.Collection; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Semaphore; public final class Pool<T> { private final BlockingQueue<T> objects; private final Semaphore permits; public Pool(Collection<? extends T> objects) { // we have as many

What is Object Pooling in Java?

女生的网名这么多〃 提交于 2019-11-27 18:00:38
What is object pooling and what is a weak object reference ? How can we implement them using Java? An object pool is a collection of a particular object that an application will create and keep on hand for those situations where creating each instance is expensive. A good example would be a database connection or a worker thread. The pool checks instances in and out for users like books out of a library. Usually object pooling is handled by a Java EE application server. If you need to do it yourself, best to use something like Apache's object pool. Don't write one yourself; thread safety and