What is the right way to access an ArrayBuffer's memory without externalizing it? I noticed that the ArrayBufferView objects have the old API (GetIndexedPropertiesExternalArrayData), because they are using that mechanism to reference into the ArrayBuffer. However, for just an ArrayBuffer and not an ArrayBufferView, how can you access the backing store? From JavaScript you cannot index into an ArrayBuffer so it makes that HasIndexedPropertiesInExternalArrayData is false. Currently it seems like the only way is to call Externalize(). Coincidently it doesn't seem valid to do if it is already external, so not only do you have to track the memory with a weak reference to free it, you also have to track the Contents / data pointer somewhere to associate it with the ArrayBuffer?
I would really prefer not to have the manage the memory lifetime, I just need to peek at the backing store for a second and copy some things out. I am already doing this for ArrayBufferViews and everything works well, but I would like to support ArrayBuffers also. There shouldn't be any worries about moving or GC, since the memory was allocated with Allocator, it should be safe just to access the pointer (of course holding the object alive with a handle). Thanks, On Thu, May 15, 2014 at 1:16 PM, Trevor Norris <[email protected]> wrote: > > On May 15, 2014 3:34 AM, "Dmitry Lomov" <[email protected]> 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? > > -- > -- > v8-users mailing list > [email protected] > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. -- -- v8-users mailing list [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
