Shared Memory - Godot 4.4+
A downloadable asset pack for Windows and Linux
This is an addon for Godot 4.4+ that adds the SharedMemory class for creating, opening and directly accessing shared memory segments for inter-process communication (IPC).
Description
SharedMemory is an IPC mechanism that lets two or more processes access the same memory segment concurrently. A segment created by one process can be read and written by other processes. Any change becomes immediately visible to all processes that share the segment.
Note: SharedMemory does not provide synchronization methods or automatic cleanup. You must synchronize concurrent access to prevent race conditions.
How to use
Write (Godot → Python):
# Godot Shared Memory Example.
extends Node
const NAME : String = "SharedMemoryExample"
const SIZE : int = 1024
func _ready() -> void:
var shm : SharedMemory = SharedMemory.new()
if shm.create(NAME, SIZE, SharedMemory.LOCAL_SCOPE) == OK:
shm.write(("Hello world from Godot Shared Memory!").to_utf8_buffer())
await get_tree().create_timer(10).timeout
shm.close()
shm.unlink()
Read (Python):
# Python Shared Memory Example.
from multiprocessing import shared_memory
from multiprocessing import resource_tracker
NAME : str = "SharedMemoryExample"
SIZE : int = 1024
def main() -> None:
shm : shared_memory.SharedMemory = shared_memory.SharedMemory(name=NAME, create=False, size=SIZE)
resource_tracker.unregister(shm._name, 'shared_memory')
data : bytes = bytes(shm.buf[:]).rstrip(b'\x00')
print(data.decode("utf-8"))
shm.close()
if __name__ == "__main__":
main()
Hello world from Godot Shared Memory!
Write (Python → Godot):
# Python Shared Memory Example.
from multiprocessing import shared_memory
import time
NAME : str = "SharedMemoryExample"
SIZE : int = 1024
def main() -> None:
shm : shared_memory.SharedMemory = shared_memory.SharedMemory(name=NAME, create=True, size=SIZE)
data : bytes = b'Hello world from Python Shared Memory!'
shm.buf[0:len(data)] = data
time.sleep(10)
shm.close()
shm.unlink()
if __name__ == "__main__":
main()
Read (Godot):
# Godot Shared Memory Example.
extends Node
const NAME : String = "SharedMemoryExample"
const SIZE : int = 1024
func rstrip(buffer : PackedByteArray) -> PackedByteArray:
var out : PackedByteArray = buffer.duplicate()
while out.size() > 0 and out[out.size() - 1] == 0:
out.resize(out.size() - 1)
return out
func _ready() -> void:
var shm : SharedMemory = SharedMemory.new()
if shm.open(NAME, SIZE) == OK:
var data : PackedByteArray = shm.read()
data = rstrip(data)
print(data.get_string_from_utf8())
shm.close()
Hello world from Python Shared Memory!
Links & Support
[ Support Email: interdreamsoft@gmail.com ]
| Published | 5 hours ago |
| Status | In development |
| Category | Assets |
| Author | InterDreamSoft |
| Tags | Asset Pack, Classes, Godot |
Purchase
In order to download this asset pack you must purchase it at or above the minimum price of $5 USD. You will get access to the following files:
Development log
- Launch Shared Memory Library.5 hours ago



Leave a comment
Log in with itch.io to leave a comment.