Shaping C-like structs into memory segments – Foreign (Function) Memory API

146. Shaping C-like structs into memory segments Let’s consider the C-like struct from the following figure: Figure 7.12 – A C-like structure So, in Figure 7.12, we have a C-like ... Read MoreRead More

0 Comments

Understanding addresses (pointers) – Foreign (Function) Memory API

144. Understanding addresses (pointers) A memory segment has a memory address (pointer) expressed as a long number. An off-heap memory segment has a physical address that points out the memory ... Read MoreRead More

0 Comments

Introducing PaddingLayout 2 – Foreign (Function) Memory API

Hooking size, alignment, stride, and padding Before continuing working with padding, we need to cover some notions which are closely related to each other and work hand in hand with ... Read MoreRead More

0 Comments

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 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