Traversing a binary
Wed Sep 22 10:36:23 CEST 2004
Method four is a worthy runner-up, and seems more generic way of parsing
binaries too. Thanks for the debate, it's been an eye-opener.
P.s. for the record:
On Wed, 22 Sep 2004 00:11:40 +0200
Erik Stenman <> wrote:
> >I assume that a bignum is an integer bigger than the word size of the
> >machine (Correct me if i'm wrong). I don't think i can have a checksum
> >bigger than 4Gb. The biggest packet i may have is 64Kb (Because of ip).
> >So, in the worst case there would be 2^15 two byte pairs. If all are
> >16#ffff that would add to 2^31, which fits in the 32 bits machine word.
> Unfortunately the tag-scheme used for Erlang takes some bits from the
> integers (i think it is 4
> bits at the moment, but it is at least 2).
> With a limited packet size it might be that bignums are created very seldom.
> >> You could also traverse the binary without creating new sub-binaries, by
> >> keeping
> >> track of how many byte-pairs you have seen (N):
> >That's something i hadn't think about. Seems a good idea.
> >I'll try it then. Maybe it's fast enough.
> If you compile to native code with hipe, then method 3 (in my small
> benchmark file) seems to be the fastest.
"The Tao of Programming
flows far away
on the wind of morning."
More information about the erlang-questions