// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;

import jdk.incubator.foreign.MemoryAddress;
import jdk.incubator.foreign.MemoryHandles;
import jdk.incubator.foreign.MemorySegment;

public class MemoryFun {
    public static void main(String[] args) {
        int[] ia = { 0x11111111, 0x11111111, 0x11111111, 0x11111111, 0x11111111 };
        MemorySegment ms = MemorySegment.ofArray(ia);
        MemorySegment ms2 = ms.asSlice(2, 16);
        VarHandle bh = MemoryHandles.varHandle(byte.class, ByteOrder.LITTLE_ENDIAN);
        MemoryAddress ma = ms2.baseAddress();
        for(int i = 0; i < 16; i++) {
            bh.set(ma.offset(i), (byte)0);
        }
        for(int i = 0; i < 5; i++) {
            System.out.printf(" %08X", ia[i]);
        }
        System.out.println();
    }
}
