-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.in
56 lines (43 loc) · 2.28 KB
/
README.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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.