# Memory (Kernel)

> Memory has several subfunctions that allow for inspecting, modifying and allocating memory dynamically.

> Important

> SCI1.1 only.

`Memory`(memALLOC_CRIT byteCount)

  Allocates memory, and crashes the game if it fails.

  Parameters: | byteCount (number) – The number of bytes to allocate.
  Returns: | A pointer to the memory block.

  Free the memory with Memory(memFREE).

  Example:

      (method (setName theName)
              (= name (Memory memALLOC_CRIT (+ (StrLen theName) 1)))
              (StrCpy name theName)
      )

`Memory`(memALLOC_NONCRIT byteCount)

  Allocates memory, returns 0 if it fails.

  Parameters: | byteCount (number) – The number of bytes to allocate.
  Returns: | A pointer to the memory block.

  Example:

      (if (not (= text (Memory memALLOC_NONCRIT 20)))
              (Prints "Couldn't allocate memory.")
      )

  Free the memory with Memory(memFREE).

`Memory`(memFREE address)

  Frees memory allocated by memALLOC or memALLOC_NONCRIT.

  Parameters: | address (heapPtr) – A pointer to the memory block.

  Example:

      (Memory memFREE blah)

`Memory`(memCPY dest source byteCount)

  Copies memory from one location to another.

  Parameters: | dest (heapPtr) – Destination address. source (heapPtr) – Source address. byteCount (number) – The number of bytes to copy.

`Memory`(memPEEK address)

  Returns the 16-bit value at the address. It’s important to note that addresses point to 16-bit values, so the address of two adjacent values in memory will be separated by 2.

  Parameters: | address (heapPtr) – A memory address.
  Returns: | The value at the address.

  Example:

      (= point (Memory memPEEK (polyPointArray + (* 2 pointIndex))))

`Memory`(memPOKE address value)

  Sets the value at a memory location.

  Parameters: | address (heapPtr) – A memory address. value (number) – The value to put at this address.

  Example:

      (Memory memPOKE (+ polyPointArray 2) 137)