Giter Site home page Giter Site logo

ewpratten / jdma Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 420 KB

Direct Memory Access and other unsafe operations for Java

Home Page: https://ewpratten.retrylife.ca/JDMA

License: GNU General Public License v3.0

Java 100.00%
java unsafe manual-memory-management no-gc off-heap dma utility library java-library

jdma's Introduction

Direct Memory Access for Java

Documentation Build library

jdma is a Java library that provides c-like malloc() and free() functions, along with many others. All functions operate off-heap, meaning no need to deal with the garbage collector. This is useful when dealing with code that must be efficient as possible.

Demo

import static ca.retrylife.jdma.DMA.*;
import static ca.retrylife.jdma.DMAString.*;

// Allocate 50 bytes
@Pointer long bytes = malloc(50);

// Set the first half to 0
memset(bytes, (byte)0, 25);

// Set the second half to 20
memset(bytes + 25, (byte)20, 25);

// Free the bytes
free(bytes);

// Reuse the bytes pointer for a c-like string
bytes = allocateString("Hello, world!");

// Truths about the string
assert strlen(bytes) == 13;
assert toJavaString(bytes, strlen(bytes)).equals("Hello, world!");

// Free the string
free(bytes);

Using in your project

Step 1. Add the RetryLife maven server to your build.gradle file:

repositories {
    maven { 
        name 'retrylife-release'
        url 'https://release.maven.retrylife.ca/' 
    }
}

Step 2. Add this library as a dependency:

dependencies {
    implementation 'ca.retrylife:jdma:1.+'
    implementation 'ca.retrylife:jdma:1.+:sources'
    implementation 'ca.retrylife:jdma:1.+:javadoc'
}

Notes

This library specifically does not use the JVM garbage collector, meaning you must free() everything when finished. All the same warnings that come with C programming apply here too. This library also comes with a @Pointer annotation, which has no effect on program execution, but just exists to visually flag values that are pointers in source code.

jdma's People

Contributors

dependabot[bot] avatar ewpratten avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.