ObjectPool/README.md

73 lines
1.8 KiB
Markdown
Raw Permalink Normal View History

2015-02-02 00:36:28 +01:00
ObjectPool
==========
###### [![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
- 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:
```
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
/**
* 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
/**
* @return a new object instance created by the pool.
*/
override fun newInstance(): Foo {
2020-10-25 13:02:14 +01:00
return Foo();
}
2017-03-09 14:44:32 +01:00
});
2015-02-02 00:36:28 +01:00
2016-02-09 18:03:18 +01: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
&nbsp;
&nbsp;
Maven Info
---------
2016-02-09 18:16:54 +01:00
```
<dependencies>
...
<dependency>
<groupId>com.dorkbox</groupId>
<artifactId>ObjectPool</artifactId>
2023-09-06 22:02:25 +02:00
<version>4.4</version>
</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 {
...
2023-09-06 22:02:25 +02:00
implementation "com.dorkbox:ObjectPool:4.4"
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
---------
This project is © 2020 dorkbox llc, and is distributed under the terms of the Apache v2.0 License. See file "LICENSE" for further
references.