import java.lang.foreign.*;

public class MemoriaNativa {

    public static void main(String[] args) {

        try (Arena arena = Arena.ofConfined()) {

            // Reservar espacio para 5 enteros
            MemorySegment datos =
                arena.allocate(
                    5 * Integer.BYTES,
                    Integer.BYTES
                );

            // Escribir valores
            for (int i = 0; i < 5; i++) {
                datos.setAtIndex(
                    ValueLayout.JAVA_INT,
                    i,
                    i * 10
                );
            }

            // Leer valores
            for (int i = 0; i < 5; i++) {
                int valor = datos.getAtIndex(
                    ValueLayout.JAVA_INT,
                    i
                );

                System.out.println(valor);
            }
        }
    }
}