Should MuBuffer constructor also take Uint8Array as argument?
hediyi opened this issue · comments
hediyi commented
could reduce some allocations in some situation like in the MuReadStream constructor
constructor (data:Uint8Array) {
this.buffer = new MuBuffer(data.buffer);
}
Mikola Lysenko commented
No. Because buffers are all pooled this could cause a memory leak.
hediyi commented
We don't pool readstream buffers. And right now new MuBuffer()
always create a new Uint8Array any way. I'm thinking something like
constructor (buffer:ArrayBuffer|Uint8Array) {
const uint8 = buffer instance of Uint8Array ? buffer : new Uint8Array(buf)
this.buffer = uint8.buffer
this.uint8 = uint8
...
}
Maybe i miss something here, how is this gonna cause a leak?
Mikola Lysenko commented
It may make stuff more complicated. One thing to consider is that we may need to track byteOffset and byteLength from the uint8array.
hediyi commented
fair point! yea, it's gonna be complicated.. closing