Skip to content

enlargeMemory does not update Module["HEAP8"] and others #713

Closed

Description

@lptr

When enlargeMemory() gets called, it updates the HEAP8, HEAP16 etc. global variables, but does not update the Module["HEAP8"], Module["HEAP16"] etc. values. This prevents callers to change/retrieve the contents of the heap after the memory has been enlarged.

A way to solve this:

function enlargeMemory() {
  while (TOTAL_MEMORY <= STATICTOP) {
    TOTAL_MEMORY = alignMemoryPage(2 * TOTAL_MEMORY);
  }
  var oldHEAP8 = HEAP8;
  var buffer = new ArrayBuffer(TOTAL_MEMORY);
  HEAP8 = new Int8Array(buffer);
  HEAP16 = new Int16Array(buffer);
  HEAP32 = new Int32Array(buffer);
  HEAPU8 = new Uint8Array(buffer);
  HEAPU16 = new Uint16Array(buffer);
  HEAPU32 = new Uint32Array(buffer);
  HEAPF32 = new Float32Array(buffer);
  HEAPF64 = new Float64Array(buffer);
  HEAP8.set(oldHEAP8);
  // +++++++++++++++++++
  Module["HEAP8"] = HEAP8;
  Module["HEAP16"] = HEAP16;
  Module["HEAP32"] = HEAP32;
  Module["HEAPU8"] = HEAPU8;
  Module["HEAPU16"] = HEAPU16;
  Module["HEAPU32"] = HEAPU32;
  Module["HEAPF32"] = HEAPF32;
  Module["HEAPF64"] = HEAPF64;
  // +++++++++++++++++++
}

Activity

  1. kripken commented on Nov 16, 2012

    @kripken
    Member

    Thanks for reporting!

  2. lptr commented on Nov 16, 2012

    @lptr
    ContributorAuthor

    Wow, thanks for the quick fix. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions