Title: | Sharing R objects across multiple R processes without memory duplication |
---|---|
Description: | This package is developed for facilitating parallel computing in R. It is capable to create an R object in the shared memory space and share the data across multiple R processes. It avoids the overhead of memory dulplication and data transfer, which make sharing big data object across many clusters possible. |
Authors: | Jiefei Wang [aut, cre], Martin Morgan [aut] |
Maintainer: | Jiefei Wang <[email protected]> |
License: | GPL-3 |
Version: | 1.21.0 |
Built: | 2024-11-30 04:34:00 UTC |
Source: | https://github.com/bioc/SharedObject |
These functions are designed for package developers only, they can allocate, open, close and destroy shared memory without touching C++ code. Normal users should not use these functions unless dealing with memory leaking
getLastIndex() allocateSharedMemory(size, name = "") mapSharedMemory(id) unmapSharedMemory(id) freeSharedMemory(id) hasSharedMemory(id) getSharedMemorySize(id) initialSharedObjectPackageData() releaseSharedObjectPackageData()
getLastIndex() allocateSharedMemory(size, name = "") mapSharedMemory(id) unmapSharedMemory(id) freeSharedMemory(id) hasSharedMemory(id) getSharedMemorySize(id) initialSharedObjectPackageData() releaseSharedObjectPackageData()
size |
The size of the shared memory that you want to allocate |
name , id
|
The name of the shared memory |
Quick explanation
getLastIndex
: the ID of the last created shared memory.
allocateSharedMemory
: allocate a shared memory of a given size,
the memory ID is returned by the function
mapSharedMemory
: map the shared memory to the current process memory space
unmapSharedMemory
: unmap the shared memory(without destroying it)
freeSharedMemory
: free the shared memory. This function will only unmap the
shared memory on Windows.
hasSharedMemory
: whether the memory exist?
getSharedMemorySize
: get the actual size of the shared memory, it may be larger than the
size that you required.
Details
A complete lifecycle of a shared memory involves four steps: allocating, mapping, unmapping and freeing the shared memory.
The shared memory can be created by allocateSharedMemory
.
The function allocateSharedMemory
will return the ID of the shared memory.
After creating the shared memory, it can be mapped to the current process by
mapSharedMemory
. The return value is an external pointer to the shared memory.
Once the shared memory is no longer needed, it can be unmapped and destroyed by
unmapSharedMemory
and freeSharedMemory
respectively.
getLastIndex
: An interger ID served as a hint of the last created shared memory ID.
allocateSharedMemory
: character ID(s) that can be used to find the shared memory
mapSharedMemory
: External pointer(s) to the shared memory
unmapSharedMemory
: No return value
freeSharedMemory
: No return value
hasSharedMemory
: Logical value(s) indicating whether the shared memory exist
getSharedMemorySize
: A numeric value
size <- 10L ## unnamed shared memory id <- allocateSharedMemory(size) hasSharedMemory(id) ptr <- mapSharedMemory(id) ptr getSharedMemorySize(id) unmapSharedMemory(id) freeSharedMemory(id) hasSharedMemory(id) ## named shared memory name <- "SharedObjectExample" if(!hasSharedMemory(name)){ allocateSharedMemory(size, name = name) hasSharedMemory(name) ptr <- mapSharedMemory(name) ptr getSharedMemorySize(name) unmapSharedMemory(name) freeSharedMemory(name) hasSharedMemory(name) }
size <- 10L ## unnamed shared memory id <- allocateSharedMemory(size) hasSharedMemory(id) ptr <- mapSharedMemory(id) ptr getSharedMemorySize(id) unmapSharedMemory(id) freeSharedMemory(id) hasSharedMemory(id) ## named shared memory name <- "SharedObjectExample" if(!hasSharedMemory(name)){ allocateSharedMemory(size, name = name) hasSharedMemory(name) ptr <- mapSharedMemory(name) ptr getSharedMemorySize(name) unmapSharedMemory(name) freeSharedMemory(name) hasSharedMemory(name) }
Whether an object is an ALTREP object
is.altrep(x)
is.altrep(x)
x |
an R object |
A logical value
This function will return the path of the shared memory header or
the flags that are used to compile the package
for the developers who want to use C++ level implementation of the
SharedObject
package
pkgconfig(x)
pkgconfig(x)
x |
Character, "PKG_LIBS" or "PKG_CPPFLAGS" |
path to the header or compiler flags
SharedObject:::pkgconfig("PKG_LIBS") SharedObject:::pkgconfig("PKG_CPPFLAGS")
SharedObject:::pkgconfig("PKG_LIBS") SharedObject:::pkgconfig("PKG_CPPFLAGS")