Construction and matching of effective erlang--binary type

Source: Internet
Author: User

In r12b, the most natural way to construct and match binary types is much faster than in the previous version. You can use the following simple code to construct a binary type:

Write this (in r12b)/Beg not to write (in the version prior to r12b)

my_list_to_binary (listmy_list_to_binary(list, <<>>).  My_list_to_binary([H|  Taccmy_list_to_binary(t, <<Acc/binary,H >>); my_list_to_binary ACC  Acc.


In a release prior to R12B, ACC is duplicated in each iteration. In r12b, ACC is replicated only in the first iteration, and after that, it opens up additional memory space. In the next iteration, H is written to additional memory. When the extra memory is full, the binary will re-expand the extra memory. The expanded memory is twice times the size of the binary, or 256, whichever is larger than the binary type.

The most natural way to match the binary type is now the fastest.

So write (in r12b)

my_binary_to_list (<<H,T/binary>>) [h|  my_binary_to_list (T)]; my_binary_to_list (<<>>), [].

Construction and matching of effective erlang--binary type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.