# Alloc

### Signatures

```csharp
u64 alloc(u64 size)
u64 alloc(u64 size, bool clear)
```

### Description

Allocates memory from the main pool, always aligned to the nearest 16 bytes.

It does not use or consume the memory reserved for [alloc-exe](https://xeavin.gitbook.io/ff12-lua-loader/memory-save/functions/alloc-exe "mention"), but may occupy other low-address regions.

Memory can, but is not guaranteed to be within 32-bit range, especially after early stages of game execution. If it is, it may be in either low or high address ranges, depending on availability and fragmentation.

Returns the starting address to the allocated memory, or `0` if allocation fails.

### Arguments

#### Size

The amount of memory to allocate, in bytes.

#### Clear

If set to `true`, the memory will be cleared. If set to `false`, the memory will remain uninitialized.

Is optional and set to `true` by default.

### Notes

{% hint style="warning" %}
Since memory is not guaranteed to be in the 32-bit address space, it should not be used with file formats that only support 32-bit pointers (mrp).
{% endhint %}

{% hint style="warning" %}
Always deallocate memory that is no longer used to avoid memory leaks.
{% endhint %}

{% hint style="info" %}
The memory that can be allocated is virtually unlimited, constrained only by the total amount of system RAM.
{% endhint %}
