AllocateMemory()

Syntax

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

Parameters

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.

Remarks

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.

Example

  *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
  Else
    Debug "Couldn't allocate the requested memory!"
  EndIf

See Also

ReAllocateMemory(), FreeMemory(), MemorySize()

Supported OS

All

Memory Index - AllocateStructure() ->