--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On May 15, 2014 3:34 AM, "Dmitry Lomov" <dsl...@chromium.org> wrote:
>
> Hi Trevor,
>
> Since V8 does not know how the memory backing an ArrayBuffer has been allocated in this case, there is now good way for V8 to free it.
Since the user has to define the ArrayBufferAllocator, V8 isn't in control of how memory is allocated regardless.
Technically using preallocated memory could be hacked in by having the user defined allocator use the user allocated memory instead. Meaning, it's possible but an inappropriate hack of the API. So I'm missing why entrusting the user to only pass in data that's been allocated properly is an issue.
> Just like previously with "external indexed data", the way to do it is to use a weak persistent handle for the ArrayBuffer to get a notification when ArrayBuffer becomes unreachable and then deal with your memory block accordingly.
This removes the performance benefit of using ArrayBuffers. I noticed how much work went in to making ArrayBuffers faster, and I would like to take advantage of this as much as possible.
One additional issue. Say ArrayBuffer is left to allocate the memory correctly. Why is it I can't simply get a pointer back out for a simple operation like memcpy() without needing to go through all this?
As it stands, the API requires that I either for loop through and copy in values or use a weak persistent handle. Neither of those are particularly appealing.
Can we work out a way to allow the user to get a pointer back from the ArrayBuffer, also have an API sanctioned way of using preallocated memory, without needing to use a weak persistent handle?
Since V8 does not know how the memory backing an ArrayBuffer has been allocated in this case, there is now good way for V8 to free it.
Since V8 does not know how the memory backing an ArrayBuffer has been allocated in this case, there is now good way for V8 to free it.
This doesn't make sense.
A part of v8::ArrayBuffer::Allocator is a Free method. When you pass an allocator to v8::V8::SetArrayBufferAllocator, you are giving V8 all the tools to both allocate and deallocate memory for an ArrayBuffer.
I see absolutely no reason why you can't make the ArrayBuffer take ownership of the memory again when you are done with it. It took ownership when it was created. If it can't take ownership again, this sounds to me like a limitation of it's implementation, not an actual virtue of its design.
I don't believe you should be able to pass any old pointer into it. I'm saying it would vastly simplify things to be able to re-internalize a previously externalized pointer.
On Thursday, September 18, 2014 11:00:10 AM UTC-8, Dmitry Lomov wrote:On Fri, Sep 12, 2014 at 11:38 PM, Flying Jester <foolki...@gmail.com> wrote:Since V8 does not know how the memory backing an ArrayBuffer has been allocated in this case, there is now good way for V8 to free it.
This doesn't make sense.
A part of v8::ArrayBuffer::Allocator is a Free method. When you pass an allocator to v8::V8::SetArrayBufferAllocator, you are giving V8 all the tools to both allocate and deallocate memory for an ArrayBuffer.You can create an ArrayBuffer over external memory (v8::ArrayBuffer::New(v8::Isolate*, void*, size_t)). V8 has no idea how this data has been allocated.
I see absolutely no reason why you can't make the ArrayBuffer take ownership of the memory again when you are done with it. It took ownership when it was created. If it can't take ownership again, this sounds to me like a limitation of it's implementation, not an actual virtue of its design.I can imagine the API where embedder says to V8: "hey ArrayBuffer I absolutely know what I am doing take ownership of this void*". The problem with that is that people usually don't, they keep the reference to the void* somewhere and later when an ArrayBuffer is garbage-collected it is use-after-free and misery. I do not have a good solution for that yet.Dmitry
It would ensure that the V8 has the correct Free method for it.
If you keep a reference to memory after you explicitly give up ownership of its lifetime and it later gets freed, that is not the library's fault.
On Thu, Sep 18, 2014 at 10:54 PM, Flying Jester <foolki...@gmail.com> wrote:
If you keep a reference to memory after you explicitly give up ownership of its lifetime and it later gets freed, that is not the library's fault.I wish it weren't :) API design is not a blame game, and this is the point of our disagreement, of course.