I am using node.js as my server platform and I need to process a non sparse array of 65,000 items.
Javascript arrays are not true arrays, but actually hashes. Index access is acpagnied with conversion of the index to string and then doing a hash lookup. (see the Arrays section in .html).
So, my question is this. Does node.js implement a real array? The one that does cost us to resize or delete items, but with the true random access without any index-to-string-then-hash-lookup ?
Thanks.
EDIT
I may be asking for too much, but my array stores Javascript objects. Not numbers. And I cannot break it into many typed arrays, each holding number primitives or strings, because the objects have nested subobjects. Trying to use typed arrays will result in an unmaintainable code.
EDIT2
I must be missing something. Why does it have to be all or nothing? Either true Javascript with no true arrays or a C style extension with no Javascript benefits. Does having a true array of Javascript (untyped) objects contradicts the nature of Javascript in anyway? Java and C# have List<Object>
which is essentially what I am looking for. C# even closer with List<DynamicObject>
.
I am using node.js as my server platform and I need to process a non sparse array of 65,000 items.
Javascript arrays are not true arrays, but actually hashes. Index access is acpagnied with conversion of the index to string and then doing a hash lookup. (see the Arrays section in http://www.crockford./javascript/survey.html).
So, my question is this. Does node.js implement a real array? The one that does cost us to resize or delete items, but with the true random access without any index-to-string-then-hash-lookup ?
Thanks.
EDIT
I may be asking for too much, but my array stores Javascript objects. Not numbers. And I cannot break it into many typed arrays, each holding number primitives or strings, because the objects have nested subobjects. Trying to use typed arrays will result in an unmaintainable code.
EDIT2
I must be missing something. Why does it have to be all or nothing? Either true Javascript with no true arrays or a C style extension with no Javascript benefits. Does having a true array of Javascript (untyped) objects contradicts the nature of Javascript in anyway? Java and C# have List<Object>
which is essentially what I am looking for. C# even closer with List<DynamicObject>
.
- regarding Edit 2 - but you said yourself, there's no such thing as a non-sparse Javascript Array. That was exactly your question, right? Keep in mind that by C-style extension, Node.js is all done in C anyway, all of it. You just write your C extension, but you can still use javascript syntax to access your node.js C extension. Also, there may already be a node.js (i.e. "C extension") for you, LLJS (see my answer). Couldn't you store your JS objects in an "LLJS Array"? – sajawikio Commented Sep 12, 2012 at 16:39
-
LLJS is a typed dialect of JavaScript that offers a C-like type system with manual memory management. It piles to JavaScript and lets you write memory-efficient and GC pause-free code less painfully, in short, LLJS is the bastard child of JavaScript and C. LLJS is early research prototype work, so don't expect anything rock solid just yet. The research goal here is to explore low-level statically typed features in a high-level dynamically typed language. Think of it as inline assembly in C, or the unsafe keyword in C#. It's not pretty, but it gets the job done.
- Not for production. – mark Commented Sep 12, 2012 at 16:42 -
@sajawikio - I know there is no such thing in Javascript as array. But node.js is a server side platform. They have the ability to extend Javascript in a fashion similar to LLJS. However, I am not in a position to adopt an
early research prototype work
. A C# likeList<DynamicObject>
is all I want and I just do not get it why there is none. – mark Commented Sep 12, 2012 at 16:45 - good point, barring the LLJS I'm not aware of anything other than the native V8 implementation (and it is, as you said, just like an ECMAscript array which is sparse) and other than just making your own implementation - maybe someone else can find something like LLJS but more mature & ready for prod use. – sajawikio Commented Sep 12, 2012 at 16:52
4 Answers
Reset to default 8Node.js has the Javascript typed arrays: Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array
.
I think they are what you are asking for.
Node.js does offer a Buffer
class that is probably what you're looking for:
A
Buffer
is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. ABuffer
cannot be resized.
Not intrinsically, no.
However depending on your level of expertise, you could write a "true" array extension using Node's C/C++ extension facility. See http://nodejs/api/addons.html
You want to use Low Level JavaScript (LLJS) to manipulate everything directly in C-style.
http://mbebenita.github./LLJS/
Notice that according to the link above, an LLJS array is more like the array you are looking for (true C-like array), rather than a Javascript array.
There is an implementation for LLJS in Node.js available , so maybe you do not have to write your own node.js C extension. Perhaps this implementation will do the trick: https://github./mbebenita/LLJS
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745594687a4635038.html
评论列表(0条)