Giter Club home page Giter Club logo

pbbl's Introduction

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.github.jhg023</groupId>
  <artifactId>Pbbl</artifactId>
  <version>1.0.2</version>
</dependency>

Gradle:

implementation 'com.github.jhg023:Pbbl:1.0.2'
  1. Because Pbbl is compiled with Java 11, you must require its module in your module-info.java:
module my.project {
    requires com.github.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);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.