Skip to content
forked from jhg023/Pbbl

ArenaReturns' fork of Pbbl, a thread-safe ByteBuffer pool that allows for the automatic reuse of ByteBuffers, which can be over 30x faster than having to allocate a new ByteBuffer when needed.

License

Notifications You must be signed in to change notification settings

ArenaReturns/Pbbl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a fork of jhg023's Pbbl library tweaked for use in Arena Returns server engine.

Pbbl (pr. pebble, pɛbəl)

A thread-safe Buffer pool that allows for the automatic reuse of Buffer objects (including ByteBuffer, CharBuffer, etc.), which can be over 30x faster than having to allocate a new Buffer.

Maven/Gradle Dependency

  1. Add Pbbl as a dependency using either Maven or Gradle:

Maven:

<dependency>
  <groupId>com.arenareturns</groupId>
  <artifactId>Pbbl</artifactId>
  <version>1.0.3</version>
</dependency>

Gradle:

implementation 'com.arenareturns:Pbbl:1.0.3'
  1. Because Pbbl is compiled with Java 11, you must require its module in your module-info.java:
module my.project {
    requires com.arenareturns.pbbl;
}

Example(s)

  1. Create ByteBufferPool and manually close it:
// Create a ByteBufferPool (used to pool non-direct ByteBuffer objects).
var pool = new ByteBufferPool();

// Take a non-direct ByteBuffer (with 8 available bytes) from the pool.
// If the pool is empty, a new ByteBuffer will be created.
var buffer = pool.take(Long.BYTES);

// Do something with the ByteBuffer.
var array = buffer.putLong(42).array();

// Give the ByteBuffer back to the pool for re-use.
pool.give(buffer);

// Close the pool when finished.
pool.close();
  1. Create DirectFloatBufferPool and automatically close it:
// Create a DirectFloatBufferPool (used to pool direct FloatBuffer objects).
try (var pool = new DirectFloatBufferPool()) {
    // Take a direct FloatBuffer (with 8 available floats) from the pool.
    FloatBuffer buffer = pool.take(8);
    
    // Do something with the FloatBuffer.
    buffer.put(42f);
    
    // Give the FloatBuffer back to the pool for re-use.
    pool.give(buffer);
}

About

ArenaReturns' fork of Pbbl, a thread-safe ByteBuffer pool that allows for the automatic reuse of ByteBuffers, which can be over 30x faster than having to allocate a new ByteBuffer when needed.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%