ewpratten / JDMA

Direct Memory Access and other unsafe operations for Java

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Direct Memory Access and other unsafe operations for Java

https://ewpratten.retrylife.ca/JDMA

License:GNU General Public License v3.0


Languages

Language:Java 100.0%