The first release for io.js is out this month, I was reading the docs when I found smalloc a new module introduced in io.js.
Till today I have never felt a need of doing so in JavaScript.
My questions are:
I wonder if there is really a need of raw memory allocation in javscript using
smalloc
?If its needed then why?
what would be the use case for using
smalloc
?and if not then why did io.js members add this module?
It also says
It's possible is to specify the type of external array data you would like. All possible options are listed in smalloc.Types
.
Example usage:
var doubleArr = smalloc.alloc(3, smalloc.Types.Double);
and here is the list of types supported for allocation
smalloc.Types#
Int8
Uint8
Int16
Uint16
Int32
Uint32
Float
Double
Uint8Clamped
- Are we trying to make javascript a strongly typed language?
First of all, buffers are backed by the smalloc module and this module was not added by io.js
devs, it was initiated in node 0.11
branch, io.js
just imported it. Raw memory allocation means a lower level of memory manipulation and thus - faster operations, better performance, which is what aims both node.js
and io.js
. So if you need to implement something in the binary world without being limited to current Buffer API you should use smalloc to create your own ways to manipulate the memory. As the docs say:
This can be used to create your own Buffer-like classes. No other properties are set, so the user will need to keep track of other necessary information (e.g. length of the allocation).
Also, this is not a try to make javascript a strongly typed language, this is just memory manipulations, it can't be done in other way ensuring higher performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With