首页 > 解决方案 > 查看 Emscripten 编译的 JS 内存数组的内存使用情况

问题描述

在 Empscripten 编译的 JS 中,我是否可以调用一些 API 来告知内存数组中已用完的空间量以及仍然可用的空间量,以便我可以在生产应用程序中为该指标添加实时检测?

我的意思是“内存数组”,如:

"Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 402653184, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which adjusts the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0

标签: emscripten

解决方案


您可以使用--memoryprofiler和调整它来达到您的目标。

但更好的解决方案是编写自己的方法 - 这是描述所需的内容https://github.com/emscripten-core/emscripten/issues/8082#issuecomment-483963811

如果您对上述解决方案不感兴趣 - 只需-s ALLOW_MEMORY_GROWTH=1按照您得到的错误建议使用(或者只是 prealloc 最大可能数量,即对于 Chrome 64 位 4GB,对于 Chrome 32 位 512 MB)。


推荐阅读