Skip to content

Allocating a >2GB pointer only seems to work when MALLOC='emmalloc' flag is set. Why isn't this documented anywhere? #17747

Description

@rotemdan

I'm using latest emscripten (3.1.20), node x64 16.17.0 on Win10 (x64).
emcc compilation is executed within WSL2 (Ubuntu 22.04.1 LTS).

I've spent some time trying to get my code (written in C) to allocate a single large matrix that may be several gigabytes in size (nothing else of significant size is allocated prior to this).

Using flags:

-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB

Didn't work when the allocated size was greater than 2GB.

After some trial and error. Going as deep as inspecting the source files, I found an option that changes the allocator from the default dlmalloc to emmaloc. Once I changed the command line to:

-s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s MAXIMUM_MEMORY=4GB -s MALLOC='emmalloc'

it worked.

Is this intended behavior? Why isn't this documented anywhere?

The most prominent Google result is a post on the V8 blog that mentions the MAXIMUM_MEMORY flag, but doesn't say anything about MALLOC?

Activity

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