Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ArrayType" takes too large heap memory. #22

Open
sookie030 opened this issue Apr 22, 2019 · 0 comments
Open

"ArrayType" takes too large heap memory. #22

sookie030 opened this issue Apr 22, 2019 · 0 comments

Comments

@sookie030
Copy link

I want to use ArrayType in ffi.
but ArrayType arrays take large memory abnormally.

My code is below.

let uint8Array = ArrayType('uint8');

console.log("start")
printHeapUsed();

let vectors = uint8Array(1);
console.log("create uint8Array(1)")
printHeapUsed()

vectors = uint8Array(10);
console.log("create uint8Array(10)")
printHeapUsed()

vectors = uint8Array(100);
console.log("create uint8Array(100)")
printHeapUsed()

vectors = uint8Array(1000);
console.log("create uint8Array(1000)")
printHeapUsed()

vectors = uint8Array(10000);
console.log("create uint8Array(10000)")
printHeapUsed()

vectors = uint8Array(100000);
console.log("create uint8Array(100000)")
printHeapUsed()

vectors = uint8Array(1000000);
console.log("create uint8Array(1000000)")
printHeapUsed()

// print used heap
function printHeapUsed() {
    let used = process.memoryUsage().heapUsed / 1024 / 1024;
    if (used < 1000)
        console.log(`heapUsed: ${Math.round(used * 100) / 100} MB\n`);
    else {
        used = used / 1024;
        console.log(`heapUsed: ${Math.round(used * 100) / 100} GB\n`);
    }
}

and result in console..

start
heapUsed: 4.53 MB

create uint8Array(1)
heapUsed: 4.56 MB

create uint8Array(10)
heapUsed: 4.57 MB

create uint8Array(100)
heapUsed: 4.62 MB

create uint8Array(1000)
heapUsed: 5.02 MB

create uint8Array(10000)
heapUsed: 8.85 MB

create uint8Array(100000)
heapUsed: 49.53 MB

create uint8Array(1000000)
heapUsed: 390.3 MB

ArrayType(ref.types.uint8).BYTES_PER_ELEMENT == 1
and I think the used heap is about 1MB with uint8Array(1000) but not.

Please tell me why. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant