-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Affects: io7m-com/.github#2
- Loading branch information
Showing
12 changed files
with
120 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
## jpuddle | ||
|
||
Java classes to pool heavyweight objects. | ||
|
||
## Features | ||
|
||
* High coverage test suite. | ||
* [OSGi-ready](https://www.osgi.org/) | ||
* [JPMS-ready](https://en.wikipedia.org/wiki/Java_Platform_Module_System) | ||
* ISC license. | ||
|
||
## Motivation | ||
|
||
Object pooling is a programming technique where instead of creating new objects | ||
to service requests, a small pool of objects is created and the objects within | ||
the pool are reused repeatedly to service requests instead. This was | ||
traditionally used by Java programs as a performance optimization in an | ||
attempt to reduce memory allocations and therefore reduce the amount of | ||
garbage collection that occurs. On modern Java virtual machines, however, | ||
object pooling as a means to improve performance in this manner is strongly | ||
contraindicated: Object allocations are extremely fast (on the order of a | ||
few tens of nanoseconds), escape analysis often eliminates allocations | ||
entirely, and modern garbage collectors are optimized to make short-lived | ||
objects essentially free. | ||
|
||
With this in mind, it may not be clear why the `com.io7m.jpuddle` package | ||
should exist at all! The answer is that object pooling is still useful when | ||
the objects represent external resources that may be very expensive to acquire | ||
and/or the program should avoid acquiring too many of these resources at any | ||
given time. An example of this sort of use case is allocating short-lived | ||
framebuffer objects on a GPU. Graphics memory is typically in relatively | ||
short supply and creating an object on the GPU is generally considered to be | ||
an expensive and slow process (relative to simply allocating an object on the | ||
CPU side). A pool of framebuffer objects can be created that the application | ||
can reuse repeatedly without needing to create new objects, and the size of the | ||
pool can be bounded so that the application does not try to exceed the | ||
available GPU memory. | ||
|
||
## Usage | ||
|
||
Implement the `JPPoolableListenerType` interface for the object you want | ||
to pool. The interface contains methods needed to estimate sizes for pool | ||
management, and methods to create and delete objects. | ||
|
||
Then, create a pool with a soft limit of `100` objects and a hard limit of | ||
`200` objects: | ||
|
||
``` | ||
JPPoolableListenerType<T> listener; | ||
|
||
var p = | ||
JPPoolSynchronous.newPool(listener, 100L, 200L); | ||
``` | ||
|
||
Use the `get()` method to retrieve objects from the pool. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
com.io7m.jpuddle.documentation/src/main/assembly/documentation.xml
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
...o7m.jpuddle.documentation/src/main/java/com/io7m/jpuddle/documentation/Documentation.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.