Re: ByteArray / Uint8Array
- From: philip chimento gmail com
- To: Giovanni Campagna <giocampagna92 gmail com>, Andrea Giammarchi <andrea giammarchi gmail com>
- Cc: javascript-list <javascript-list gnome org>
- Subject: Re: ByteArray / Uint8Array
- Date: Fri, 10 Nov 2017 04:29:38 +0000
Hi Andrea and Giovanni,
Thanks for the replies and for thinking about the problem.
just thinking about this, how about you keep ByteArray as it is, deprecating it, and you introduce a global Buffer still based on UInt8Array ?
It's unfortunately not possible to keep everything as it is while still switching to Uint8Array - functions that take a byte array as an input parameter could accept any of ByteArray, Uint8Array or a new Buffer class, but functions that return a byte array would need to choose which one they return. If they continue to return ByteArray then there's not as much benefit in switching, in my opinion.
in cgjs I've just done `require("buffer")` which brings in the node version of a buffer which is already based on native Uint8Array
I will check that out, thanks.
it'd be awkward to move back and forward from ByteArray <=> Buffer/Uint8Array in the transition time, so having a new primitive already well documented might be a better option?
otherwise I personally wouldn't care as long as it's backward compatible
It may be possible to write a work-alike ByteArray replacement in JS, even if it's not zero-copy. I've started to do that but have not had time to continue it the past few days. Hopefully the Buffer code might give me some ideas.
There is JS_NewArrayBufferWithExternalContents() [1], but it looks like it won't exactly play well with a refcounted GBytes. What would really be nice here is a way to create an ArrayBuffer that calls a callback when it's released so that you can unref the GBytes, but that doesn't exist.
That may even already work, I'm not sure. I will check. I like the idea of getting a Uint8Array from GBytes.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]