Subj : Re: spidermonkey: byte arrays - again To : netscape.public.mozilla.jseng From : Shanti Rao Date : Thu Sep 16 2004 02:04 pm Jens, What are you using it for? Arbitrary indexing and manipulation, or sequential scanning of text? Do you need to do myarray[5] or myarray.seek(5) myarray.read(2) How much data do you want to store? Do you need the array to be resizable? Is it write-once-read-many or random-access? Do you need bulk mathematical operations? Do you want to read the values as numbers or as characters? I'vd found that a JS Array of 10k floating-point numbers works just fine for light computation. Shanti > Hi, > > I am at the byte arrays again ;-) > > Intro: > Unfortunately Javascript does not have a native/primtive c-style byte > array for raw data. Especially when wrapping native code you need it. > (For example networking, image processing, compression/decompression, > ...) > > Possible "solutions": > 1. use javascript string: > a) only use 8bit of 16bit chars > + simple > - bloat > - confusing / error prone > b) use all 16 bit > - what about odd number of bytes? needs some ugly hack > > 2. use javascript array: > I only did a quick look at how the arrays are done and guess > this would be real bloat > > 3. write some native/host object: > + efficient (memory and cpu) > - no literal notation => solution 1 or 2 needed to get > something close to a literal notation: > new ByteArray("thisisraw8bitdatastoredin16bit") > new ByteArray([10,20,30,...]) > new ByteArray("\u3744\u....",odd|even) or similar hack > > probably best thread for implementing 3: > http://groups.google.de/groups?th=35ba422a08cd0319 > > > Now the real question: > Did someone write a ByteArray object/class and wants to share the code? > > Thanks > Jens .