TypedArray data access and memory allocation behavior threshold

38 views
Skip to first unread message

Zach Bjornson

unread,
Jul 29, 2015, 5:05:15 PM7/29/15
to v8-users
Some of this has been discussed before, but the API has changed a lot recently and I'm lost a bit in the discussion.

In v8 4.2.77.20 (version in iojs 2.4.0) the following seems to work for arrays *larger than 64 bytes:*

    Local<Uint8ClampedArray> arr = args[0].As<Uint8ClampedArray>();
    void *data = arr->GetIndexedPropertiesExternalArrayData();


For arrays smaller than 64 bytes, data is 0. I'm guessing this is an artifact of small arrays being sliced off from a shared buffer while larger arrays are assigned their own memory? I'm not sure if this is even supposed to work. Trevor Norris asked in November and didn't get a reply (https://groups.google.com/forum/#!msg/v8-dev/qathcB2-M-A/MVKwE8oHVH4J).

As far as I understand, the Get/SetIndexedProperties... API is being removed in v8 4.3 and the proper interface there is ArrayBuffer::GetContents (to not externalize the ArrayBuffer) (discussed here, here and here). Is all that correct?

Thanks,
Zach

Jochen Eisinger

unread,
Jul 30, 2015, 3:39:10 AM7/30/15
to v8-u...@googlegroups.com
On Wed, Jul 29, 2015 at 11:05 PM Zach Bjornson <zbbjo...@gmail.com> wrote:
Some of this has been discussed before, but the API has changed a lot recently and I'm lost a bit in the discussion.

In v8 4.2.77.20 (version in iojs 2.4.0) the following seems to work for arrays *larger than 64 bytes:*

    Local<Uint8ClampedArray> arr = args[0].As<Uint8ClampedArray>();
    void *data = arr->GetIndexedPropertiesExternalArrayData();


For arrays smaller than 64 bytes, data is 0. I'm guessing this is an artifact of small arrays being sliced off from a shared buffer while larger arrays are assigned their own memory? I'm not sure if this is even supposed to work. Trevor Norris asked in November and didn't get a reply (https://groups.google.com/forum/#!msg/v8-dev/qathcB2-M-A/MVKwE8oHVH4J).


V8 can store the elements directly on the object, the (configurable) upper bound for this is indeed 64 bytes. If you want to access them as an external array, you can get the buffer from the typed array, that'll change the representation to use an external array.
 
As far as I understand, the Get/SetIndexedProperties... API is being removed in v8 4.3 and the proper interface there is ArrayBuffer::GetContents (to not externalize the ArrayBuffer) (discussed here, here and here). Is all that correct?

yes. GetContents works independently of whether the data is in external array or on heap.

best
-jochen
 
Thanks,
Zach

--
--
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.
Reply all
Reply to author
Forward
0 new messages