Skip to content

Commit

Permalink
Add SharedMemoryArray.getNameForPython()
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed Apr 19, 2024
1 parent 353c167 commit 6042b3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/apposed/appose/shm/SharedMemoryArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ static SharedMemoryArray read(String name) {
*/
String getName();

/**
* Get the unique name for this shared memory segment, as the Python package
* {@code multiprocessing.shared_memory} requires it.
* <p>
* For Unix based systems it removes the initial {@code "/"}, for example,
* {@code "/shm_block"} becomes {@code "shm_block"}. In Windows shared
* memory block names start either with {@code "Global\\"} or {@code
* "Local\\"}, this is also removed when providing a shared memory name to
* Python. For Example, {@code "Local\\shm_block"} becomes {@code
* "shm_block"}.
*
* @return the unique name for the shared memory, for use in Python.
*/
String getNameForPython();

/**
* @return the pointer to the shared memory segment
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public String getName() {
return memoryName;
}

@Override
public String getNameForPython() {
return memoryName.substring("/".length());
}

@Override
public Pointer getPointer() {
return pSharedMemory;
Expand Down

0 comments on commit 6042b3f

Please sign in to comment.