Skip to content

Module._malloc is not a function #6882

@yahsaves

Description

@yahsaves

I'm trying to compile my project in such a way that I can pass a javascript typed array into an exported wasm function.

From every tutorial I read online in order to do this I have to copy the buffer of the typed array into the wasm heap like this:

var buf = Module._malloc(desiredLength);
Module.HEAPU8.set(typedArray, buf);
Module.ccall('my_function', 'number', ['number'], [buf]);

However when I try to run this code in the browser I get this error:

Module._malloc is not a function

This is what I am using to compile my c++ code:

emcc myProject.cpp -s WASM=1 -s EXPORTED_FUNCTIONS="['_processData']" -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -O3 -o index.js

Is there any reason for this error? Did I set something up incorrectly? Any help would be much appreciated.

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