Skip to content

Error with malloc and memory limit #521

@serman

Description

@serman

HelloI
I am posting here since it could be useful for others too.
(edit: sorry, after submitting, I am realising this message should go to the discussion board)

have received a new version of the model and I found a "random" error related with the outputs.
The model is generated correctly but when I run it I find this error:

image

After removing some variables form the output.csv file I realized that the problem was not caused by any of them but by having too many. I managed to add the -S ASSERTIONS=1 to the wasm plugin: 

wasmPlugin({ 
emccArgs: [
"-Wall", "-Os ", 
"-sSTRICT=1 ",
 "-sMALLOC=emmalloc", 
"-sFILESYSTEM=0 ",
 "-sMODULARIZE=1 ",
 "-sSINGLE_FILE=1 ", 
"-sEXPORT_ES6=1 ",
 "-sUSE_ES6_IMPORT_META=0 ", 
"-sENVIRONMENT='web,webview,worker' ", 
"-sEXPORTED_FUNCTIONS='_malloc','_free','_getInitialTime','_getFinalTime','_getSaveper','_setLookup','_runModelWithBuffers']", 
"-sEXPORTED_RUNTIME_METHODS=['cwrap']",
 "-sASSERTIONS=1"] }),

(note: I recommend including an example of this in the documentation since I didn't know that -s params don't have a space between "-s XXXXPARAMXXX" I can add it if you want)

And the error I got was:
image

Which, as suspected, is due to excess memory consumption.
Adding: -sINITIAL_MEMORY=32MB,or -sALLOW_MEMORY_GROWTH=1

seems to fix the problem. 
What do you recommend? Do you think we can get into trouble by using 32MB? It doesn't seem like a lot for an application but I am not familiar with WASM limitations.
Rgds

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