2015-02-02 00:36:28 +01:00
ObjectPool
==========
2020-10-06 19:55:17 +02:00
###### [![Dorkbox](https://badge.dorkbox.com/dorkbox.svg "Dorkbox")](https://git.dorkbox.com/dorkbox/ObjectPool) [![Github](https://badge.dorkbox.com/github.svg "Github")](https://github.com/dorkbox/ObjectPool) [![Gitlab](https://badge.dorkbox.com/gitlab.svg "Gitlab")](https://gitlab.com/dorkbox/ObjectPool)
2019-03-17 22:57:17 +01:00
2016-02-09 18:16:54 +01:00
This provides an ObjectPool, for providing for a safe, and fixed sized pool of objects. This is only recommended in systems were garbage collection is to be kept to a minimum, and the created objects are large.
2015-02-02 00:36:28 +01:00
2020-10-06 19:55:17 +02:00
- This is for cross-platform use, specifically - linux 32/64, mac 32/64, and windows 32/64. Java 11+
2015-02-02 00:36:28 +01:00
Usage:
```
2020-10-06 19:55:17 +02:00
val < T > pool = ObjectPool.nonBlocking(PoolObject< T > () {
/**
* Called when an object is returned to the pool, useful for resetting an objects state, for example.
*/
fun onReturn(`object`: Foo) {
object.foo = 0;
object.bar = null;
}
2017-03-09 14:44:32 +01:00
2020-10-06 19:55:17 +02:00
/**
* Takes an object from the pool, if there is no object available, will create a new object.
*/
fun onTake(`object`: Foo) {
}
2017-03-09 14:44:32 +01:00
2020-10-06 19:55:17 +02:00
/**
* @return a new object instance created by the pool.
*/
override fun newInstance(): Foo {
2020-10-25 13:02:14 +01:00
return Foo();
2020-10-06 19:55:17 +02:00
}
2017-03-09 14:44:32 +01:00
});
2015-02-02 00:36:28 +01:00
2016-02-09 18:03:18 +01:00
2020-10-06 19:55:17 +02:00
val foo = pool.take()
pool.put(foo)
2015-02-02 00:36:28 +01:00
```
2016-02-09 18:16:54 +01:00
2017-02-18 23:59:18 +01:00
Maven Info
---------
2016-02-09 18:16:54 +01:00
```
2017-07-23 18:03:25 +02:00
< dependencies >
...
< dependency >
< groupId > com.dorkbox< / groupId >
< artifactId > ObjectPool< / artifactId >
2022-04-03 17:28:55 +02:00
< version > 3.6< / version >
2017-07-23 18:03:25 +02:00
< / dependency >
< / dependencies >
2016-02-09 18:16:54 +01:00
```
2018-08-18 20:38:22 +02:00
Gradle Info
---------
2020-10-20 01:08:00 +02:00
```
2018-08-18 20:38:22 +02:00
dependencies {
...
2022-04-03 17:28:55 +02:00
implementation "com.dorkbox:ObjectPool:3.6"
2018-08-18 20:38:22 +02:00
}
````
2018-08-18 20:57:13 +02:00
2017-02-18 23:59:18 +01:00
License
---------
2020-10-06 19:55:17 +02:00
This project is © 2020 dorkbox llc, and is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further
references.
2016-02-10 03:34:17 +01:00