我正在尝试测试 Java 21 的外部函数和内存功能。这是我的代码:
\npublic static void main(String[] args) {\n // 1. Find foreign function on the C library path\n Linker linker = Linker.nativeLinker();\n SymbolLookup stdlib = linker.defaultLookup();\n MethodHandle radixsort = linker.downcallHandle(stdlib.find("radixsort").orElseThrow(), FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.JAVA_CHAR));\n // 2. Allocate on-heap memory to store four strings\n String[] javaStrings = {"mouse", "cat", "dog", "car"};\n\n // 3. Use try-with-resources to manage the lifetime of off-heap memory\n try (Arena offHeap = Arena.ofConfined()) {\n // 4. Allocate a region of off-heap memory to store …
Run Code Online (Sandbox Code Playgroud)