All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jtransc.util.JTranscMemAllocator Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
package com.jtransc.util;

import com.jtransc.FastMemory;

public class JTranscMemAllocator {
	public final int totalSize;
	private int offset = 0;

	public JTranscMemAllocator(int totalSize) {
		this.totalSize = totalSize;
	}

	public JTranscMemAllocator(FastMemory mem) {
		this.totalSize = mem.getLength();
	}

	public int malloc(int size) {
		if (offset + size > totalSize) throw new RuntimeException("No enough space!");
		try {
			return offset;
		} finally {
			offset += size;
		}
	}

	// @TODO: No free! So this is much easier to implement. To create simple layouts along with Mem.
	//public void free(int offset) {
	//}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy