[whatwg] Cryptographically strong random numbers

Brendan Eich brendan at mozilla.org
Mon Feb 14 16:47:51 PST 2011


On Feb 14, 2011, at 3:03 PM, Allen Wirfs-Brock wrote:

> And why overwrite the elements of an existing array?  Why not just creating a new Array and use the argument to specify the desired length?

Just to respond to this, I believe the reusable buffer is an optimization (premature? perhaps not for those JS VMs that lack super-fast generational GC) to allow the API user to amortize allocation overhead across many calls to getRandomValues. Of course, with a fast enough GC or few enough calls, this optimization doesn't matter.

The IDL's use of an array inout parameter also supports efficient bindings for languages with stack allocation, which is a non-trivial win in C and C++ not only compared to malloc performance-wise, but also for automated cleanup (vs. intrinsic cost of free, plus on some OSes, "which free do I call"?).

/be


More information about the whatwg mailing list