Skip to content

Commit

Permalink
Make ShmInfo track the *requested* size
Browse files Browse the repository at this point in the history
On macOS, the size of the allocated shared memory block might not
precisely match the request. But it needs to be at least as large as
the requested size. E.g.: sizes less than 16384 round up to 16384.

When asking the SharedMemory object for its size, we should remember the
requested size and return that value, rather than the rounded up one.
  • Loading branch information
ctrueden committed Sep 24, 2024
1 parent 59461a8 commit 5fff306
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/apposed/appose/shm/ShmBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ protected static class ShmInfo<HANDLE> {
/** Size in bytes. */
int size;

/** Size in bytes allocated by the operating system. */
int totalSize;

/** Pointer referencing the shared memory. */
Pointer pointer;

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apposed/appose/shm/ShmLinux.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ private static ShmInfo<Integer> prepareShm(String name, boolean create, int size
}

ShmInfo<Integer> info = new ShmInfo<>();
info.size = shm_size;
info.size = size;
info.totalSize = shm_size;
info.name = withoutLeadingSlash(shm_name);
info.pointer = pointer;
info.handle = shmFd;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apposed/appose/shm/ShmMacOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ private static ShmInfo<Integer> prepareShm(String name, boolean create, int size
}

ShmInfo<Integer> info = new ShmInfo<>();
info.size = shm_size;
info.size = size;
info.totalSize = shm_size;
info.name = withoutLeadingSlash(shm_name);
info.pointer = pointer;
info.handle = shmFd;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apposed/appose/shm/ShmWindows.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ private static ShmInfo<WinNT.HANDLE> prepareShm(String name, boolean create, int
}

ShmInfo<WinNT.HANDLE> info = new ShmInfo<>();
info.size = shm_size;
info.size = size;
info.totalSize = shm_size;
info.name = shm_name;
info.pointer = pointer;
info.writePointer = writePointer;
Expand Down

0 comments on commit 5fff306

Please sign in to comment.