Lua:allocateSharedMemory
Jump to navigation
Jump to search
Creates or opens a named shared memory object and maps it into the currently targeted process.
If a shared memory object with the given name does not exist yet, Cheat Engine creates it with the specified size. If size is not provided and no shared memory object with that name exists, the default size of 4096 bytes is used.
The function returns the address where the shared memory block is mapped in the target process.
Contents
Function Parameters
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the shared memory object. |
| size | Integer (optional) | The size of the shared memory object to create if it does not exist yet. If omitted, the default size is 4096 bytes. |
Returns
Integer — The address of the mapped shared memory region in the target process.
Examples
local address = allocateSharedMemory("MySharedMemory", 4096)
print("Shared memory mapped at: " .. string.format("%X", address))
local address = allocateSharedMemory("MySharedMemory")
if address ~= nil and address ~= 0 then
writeInteger(address, 1234)
print("Value written to shared memory")
end
local sharedAddress = allocateSharedMemory("SharedCounter", 4096)
if sharedAddress ~= nil and sharedAddress ~= 0 then
local currentValue = readInteger(sharedAddress) or 0
writeInteger(sharedAddress, currentValue + 1)
print("Counter: " .. tostring(readInteger(sharedAddress)))
end
Notes
- The shared memory object is mapped into the currently targeted process.
- If the named shared memory object already exists, the existing object is used.
- If size is omitted and the object does not exist yet, 4096 bytes are used.
- A process can map the same shared memory block multiple times.
- Keep track of the addresses returned by this function.
- Use a unique name to avoid unintentionally reusing an existing shared memory object.