Difference between revisions of "Lua:allocateMemory"

From Cheat Engine
Jump to navigation Jump to search
(Created page with "Category:Lua '''function''' allocateMemory(''size'', ''BaseAddress'' '''''OPTIONAL''''', ''Protection'' '''''OPTIONAL''''') Allocates a specified size of memory into the...")
 
m (Syntax Highlighting.)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' allocateMemory(''size'', ''BaseAddress'' '''''OPTIONAL''''', ''Protection'' '''''OPTIONAL''''')
+
{{CodeBox|'''function''' allocateMemory(''size'', ''BaseAddress'', ''Protection'') ''':''' integer}}
  
Allocates a specified size of memory into the target process.
+
Allocates memory in the target process.
  
 +
The optional ''BaseAddress'' parameter can be used to specify a preferred base address for the allocation. The optional ''Protection'' parameter can be used to specify the memory protection for the allocated region.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|Size
+
|size
 
|Integer
 
|Integer
|The size of memory to allocate.
+
|The number of bytes to allocate in the target process.
 
|-
 
|-
|Base Address
+
|BaseAddress
|Integer
+
|Integer or [[CEAddressString]] (optional)
|The address of the location to allocate memory.
+
|The preferred base address for the allocation.
 
|-
 
|-
 
|Protection
 
|Protection
|Boolean
+
|Integer or String (optional)
|Protect the allocated memory, or not.
+
|The memory protection to use for the allocated region.
 
|}
 
|}
 +
 +
===Returns===
 +
integer — The address of the allocated memory block.
 +
 +
===Examples===
 +
<syntaxhighlight lang="lua" line>
 +
local address = allocateMemory(1024)
 +
 +
print("Allocated memory at: " .. string.format("%X", address))
 +
 +
deAlloc(address)
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="lua" line>
 +
local baseAddress = getAddress("game.exe")
 +
local address = allocateMemory(2048, baseAddress)
 +
 +
print("Allocated memory at: " .. string.format("%X", address))
 +
 +
deAlloc(address)
 +
</syntaxhighlight>
 +
 +
{{LuaSeeAlso}}
 +
 +
{{Memory}}

Latest revision as of 16:31, 25 June 2026

<> Lua API Reference

function allocateMemory(size, BaseAddress, Protection) : integer

Allocates memory in the target process.

The optional BaseAddress parameter can be used to specify a preferred base address for the allocation. The optional Protection parameter can be used to specify the memory protection for the allocated region.

Function Parameters[edit]

Parameter Type Description
size Integer The number of bytes to allocate in the target process.
BaseAddress Integer or CEAddressString (optional) The preferred base address for the allocation.
Protection Integer or String (optional) The memory protection to use for the allocated region.

Returns[edit]

integer — The address of the allocated memory block.

Examples[edit]

1 local address = allocateMemory(1024)
2 
3 print("Allocated memory at: " .. string.format("%X", address))
4 
5 deAlloc(address)
1 local baseAddress = getAddress("game.exe")
2 local address = allocateMemory(2048, baseAddress)
3 
4 print("Allocated memory at: " .. string.format("%X", address))
5 
6 deAlloc(address)

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Sections / Views

Memory Mapping

Memory Copy / Compare

Memory Streams