miktam / sizeof

Get size of a JavaScript object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typed array sizes overestimated

romainbar opened this issue · comments

let a = new Uint8Array(50);
sizeof(a); // 580
a.length; // 50

Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array... need be detected.
Such as:
if (a.constructor === Int8Array || a.constructor === Uint8Array || a.constructor === Uint8ClampedArray
|| a.constructor === Int16Array || a.constructor === Uint16Array)
{
size = a.BYTES_PER_ELEMENT * a.length;
}

@miktam will the changes of @daneren2005 (daneren2005@21428d8) be merged? this is a useful contribution.

@ martin19, it seems useful.
@daneren2005, could you make a PR, please?

awesome, thanks!