Traversing a binary

Erik Stenman <>
Wed Sep 22 00:11:40 CEST 2004


Javier París Fernández 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.

/Erik



More information about the erlang-questions mailing list