Discussion:
[dart-misc] Typed data (views) and heterogeneous buffer
Rez
2016-10-17 15:21:08 UTC
Permalink
I am currently writing a loader for a binary format. The format is
chunk-based. I'm stuck at reading numeric array types. I'm using typed data
views to access the chunk content based on their type. The problem I found
is that I can't use arbitrary offset for typed data views; the offset must
be multiple of the element size in bytes.

An example
here: https://dartpad.dartlang.org/24c8e870735d400f2f5b77d1d1d7a57a

1. Is there any work around, which works efficiently without unnecessary
copying?

2. A question for Dart team: why the offset must be multiple of the element
size? Isn't it actually unnecessary? I mean the offset has been checked
that must be 0 or positive (range check), same with the element accessor
index.
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Bob Nystrom' via Dart Misc
2016-10-17 16:11:26 UTC
Permalink
You want a Byte*Data*
<https://api.dartlang.org/stable/1.20.1/dart-typed_data/ByteData-class.html>
instead of a Byte*Buffer*, I think.

– bob
Post by Rez
I am currently writing a loader for a binary format. The format is
chunk-based. I'm stuck at reading numeric array types. I'm using typed data
views to access the chunk content based on their type. The problem I found
is that I can't use arbitrary offset for typed data views; the offset must
be multiple of the element size in bytes.
An example here: https://dartpad.dartlang.org/
24c8e870735d400f2f5b77d1d1d7a57a
1. Is there any work around, which works efficiently without unnecessary
copying?
2. A question for Dart team: why the offset must be multiple of the
element size? Isn't it actually unnecessary? I mean the offset has been
checked that must be 0 or positive (range check), same with the element
accessor index.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
'Vyacheslav Egorov' via Dart Misc
2016-10-17 16:13:09 UTC
Permalink
Hi,

1. You can use ByteData class to access unaligned data, see:

https://api.dartlang.org/stable/1.20.1/dart-typed_data/ByteData-class.html

2. dart:typed_data in general matches how typed arrays work in the browser
(previously specified by WebGL, now included into ES6 specification). And
the main reasoning for imposing alignment requirements is that it allows
you to efficiently access the data (i.e. some architectures don't support
accessing unaligned data at all - you need to load it byte-by-byte and
assemble manually).
Post by Rez
I am currently writing a loader for a binary format. The format is
chunk-based. I'm stuck at reading numeric array types. I'm using typed data
views to access the chunk content based on their type. The problem I found
is that I can't use arbitrary offset for typed data views; the offset must
be multiple of the element size in bytes.
https://dartpad.dartlang.org/24c8e870735d400f2f5b77d1d1d7a57a
1. Is there any work around, which works efficiently without unnecessary
copying?
2. A question for Dart team: why the offset must be multiple of the
element size? Isn't it actually unnecessary? I mean the offset has been
checked that must be 0 or positive (range check), same with the element
accessor index.
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
// Vyacheslav Egorov
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
Loading...