Difference between revisions of "Lua:allocateSharedMemory"

From Cheat Engine
Jump to navigation Jump to search
m
m (Syntax Highlighting.)
 
Line 27: Line 27:
  
 
===Examples===
 
===Examples===
<pre>
+
<syntaxhighlight lang="lua" line>
 
local address = allocateSharedMemory("MySharedMemory", 4096)
 
local address = allocateSharedMemory("MySharedMemory", 4096)
  
 
print("Shared memory mapped at: " .. string.format("%X", address))
 
print("Shared memory mapped at: " .. string.format("%X", address))
</pre>
+
</syntaxhighlight>
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local address = allocateSharedMemory("MySharedMemory")
 
local address = allocateSharedMemory("MySharedMemory")
  
Line 40: Line 40:
 
   print("Value written to shared memory")
 
   print("Value written to shared memory")
 
end
 
end
</pre>
+
</syntaxhighlight>
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local sharedAddress = allocateSharedMemory("SharedCounter", 4096)
 
local sharedAddress = allocateSharedMemory("SharedCounter", 4096)
  
Line 51: Line 51:
 
   print("Counter: " .. tostring(readInteger(sharedAddress)))
 
   print("Counter: " .. tostring(readInteger(sharedAddress)))
 
end
 
end
</pre>
+
</syntaxhighlight>
  
 
===Notes===
 
===Notes===

Latest revision as of 16:31, 25 June 2026

<> Lua API Reference

function allocateSharedMemory(name, size) : integer

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.

Function Parameters[edit]

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[edit]

Integer — The address of the mapped shared memory region in the target process.

Examples[edit]

1 local address = allocateSharedMemory("MySharedMemory", 4096)
2 
3 print("Shared memory mapped at: " .. string.format("%X", address))
1 local address = allocateSharedMemory("MySharedMemory")
2 
3 if address ~= nil and address ~= 0 then
4   writeInteger(address, 1234)
5   print("Value written to shared memory")
6 end
1 local sharedAddress = allocateSharedMemory("SharedCounter", 4096)
2 
3 if sharedAddress ~= nil and sharedAddress ~= 0 then
4   local currentValue = readInteger(sharedAddress) or 0
5   writeInteger(sharedAddress, currentValue + 1)
6 
7   print("Counter: " .. tostring(readInteger(sharedAddress)))
8 end

Notes[edit]

  • 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.

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Sections / Views

Memory Mapping

Memory Copy / Compare

Memory Streams