*MemoryID = AllocateMemory(Size [, Flags])
Allocates a contiguous memory area with the specified size in bytes. The new memory area will be cleared and filled with zeros.


Size The size in bytes for the new memory area.
Flags (optional) It can be one of the following values:
  #PB_Memory_NoClear: don't fill the new memory area with zeros. It can help to have faster allocation if the
                      allocated memory is used immediately.

Return value

Returns the address of the allocated memory, or zero if the memory cannot be allocated.


FreeMemory() can be used to return the allocated memory back to the system. ReAllocateMemory() can be used to change the size of the allocated area. All the allocated memory areas are automatically freed when the programs ends.

If the program crashes at this command, it is usually a result of a memory corruption at an earlier time in the program by writing at an area outside of the allocated memory area. Such an error can be narrowed down to the real cause using the purifier debugger tool.


  *MemoryID = AllocateMemory(5000)
  If *MemoryID
    Debug "Starting address of the 5000 Byte memory area:"
    Debug *MemoryID
    PokeS(*MemoryID, "Store this string in the memory area")
    FreeMemory(*MemoryID)  ; will also be done automatically at the end of program
    Debug "Couldn't allocate the requested memory!"

See Also

ReAllocateMemory(), FreeMemory(), MemorySize()

Supported OS


Memory Index - AllocateStructure() ->