Replies: 1 comment
-
Hello, sorry for the long wait due to the Chinese New Year. The device has a limit on the total amount of memory JS can run on, reading a 200KB file at once can easily lead to such an error, so we suggest cutting the file into smaller units or reading the whole file in sections. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to read a txt file from asset/raw directory. When testing the app in the simulator, it works. However, when I test the app on GTR4 device, I get the "out of memory" error. The file is of size on the order of 200 KB.
The code I use for file reading is as follows (.):
export function readAssetFileSync(filename, options) {
logger.log('readAssetFileSync fiename:', filename)
const fs_stat = statSyncAsset(filename)
if (!fs_stat) return undefined
// the out of memory error occurs here
const destination_buf = new Uint8Array(fs_stat.size)
const file = hmFS.open_asset(filename, hmFS.O_RDONLY)
hmFS.seek(file, 0, hmFS.SEEK_SET)
hmFS.read(file, destination_buf.buffer, 0, fs_stat.size)
hmFS.close(file)
const content = ab2str8(destination_buf.buffer)
//logger.log('readAssetFileSync', content)
return content
}
Beta Was this translation helpful? Give feedback.
All reactions