Skip to content

why users has to go through 2 rounds of copying? #58

@SmartLayer

Description

@SmartLayer

Observe the test case:

function getCorrectBuffer(content)
{
const arrayBuffer = new ArrayBuffer(content.length);
const uint8Array = new Uint8Array(arrayBuffer);
for(let i = 0; i < content.length; i++)
uint8Array[i] = content[i];
return arrayBuffer.slice(0);
}

The file being read is copied into a new ArrayBuffer (line 17), which is in turn copied to a new one (line 20 with slice() Returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer).

Why the same data has to be copied 2 times? If the underlying data is 1GB, that is 2GB additonal memory being used (although the intermediary 1GB will be released once the function ends). Just curious.

P.S. in our applications we tried to feed the Buffer returnd directly from ReadFileSync or the ArrayBuffer of that Buffer, all failed with this error. The only way that works is to honestly copy 2 times just like you did.

		throw new Error("Object's schema was not verified against input data for MyModule");
		      ^

Can you fix this issue by adding a line of comment before the line 12 reasoning the 2× copying?

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