Introducing memory segment view VarHandle – Foreign (Function) Memory API

155. Introducing memory segment view VarHandle Let’s consider the following simple memory segment for storing an int (arena is an instance of Arena): MemorySegment segment = arena.allocate(ValueLayout.JAVA_INT); We know that ... Read MoreRead More

0 Comments

Introducing PaddingLayout 4 – Foreign (Function) Memory API

Adding explicit extra space (explicit padding) to validate alignment Let’s consider the following C-like struct (let’s denote this as Case 1): StructLayout product = MemoryLayout.structLayout(  ValueLayout.JAVA_INT.withName(“sku”),  ValueLayout.JAVA_CHAR.withName(“energy”),  ValueLayout.JAVA_BYTE.withName(“weight”)); The product ... Read MoreRead More

0 Comments

Tackling mapped memory segments – Foreign (Function) Memory API

157. Tackling mapped memory segments We know that a computer has limited physical memory referred to as RAM memory. Common sense though tells us that we cannot allocate a memory ... Read MoreRead More

0 Comments

Introducing PaddingLayout 3 – Foreign (Function) Memory API

Hooking stride The minimum byte-distance between two member layouts is called stride. The stride can be greater than or equal to the size. When we don’t face any alignment issues ... Read MoreRead More

0 Comments

Copying and slicing memory segments 2 – Foreign (Function) Memory API

Copying a part of the segment into another segment (2) Let’s consider the srcSegment (1, 2, 3, 4, -1, -1, -1, 52, 22, 33, -1, -1, -1, -1, -1, 4) ... Read MoreRead More

0 Comments

Copying and slicing memory segments – Foreign (Function) Memory API

149. Copying and slicing memory segments Let’s consider the following memory segment (arena is an instance of Arena): MemorySegment srcSegment = arena.allocateArray(  ValueLayout.JAVA_INT, 1, 2, 3, 4, -1, -1, -1,                        ... Read MoreRead More

0 Comments

Introducing Foreign Linker API – Foreign (Function) Memory API

158. Introducing Foreign Linker API The main goal of Foreign Linker API is to provide a robust and easy-to-use API (no need to write C/C++ code) for sustaining interoperability between ... Read MoreRead More

0 Comments

Calling the sumTwoInt() foreign function – Foreign (Function) Memory API

159. Calling the sumTwoInt() foreign function Do you remember the sumTwoInt() function? We have defined this C function in a native shared library named math.dll (check Problems 137, 138, and ... Read MoreRead More

0 Comments

Tackling the slicing allocator – Foreign (Function) Memory API

150. Tackling the slicing allocator Let’s consider the following three Java regular int arrays: int[] arr1 = new int[]{1, 2, 3, 4, 5, 6};int[] arr2 = new int[]{7, 8, 9};int[] ... Read MoreRead More

0 Comments

Calling the strcat() foreign function – Foreign (Function) Memory API

161. Calling the strcat() foreign function The strcat() foreign function is part of the C standard library and it has the following signature (https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strcat-wcscat-mbscat): char *strcat(char *strDestination, const char *strSource); ... Read MoreRead More

0 Comments