Golang Slice Append

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.
S2: = Append (S1, *)


The slice information recorded on the slice S1 is copied to S2,

1. If the underlying array length that the S1 points to is not sufficient, the append process will take the following actions: Not only is the new area stored in memory a append slice of information, It also requires a new area to store the underlying array (copying the original array into the new array), and then append the new data into the new array, so that S2 points to the new array.

2. If the bottom array length of the S1 point is sufficient,
the result of S2 and S1 pointing to the same array,append is a new area in memory that stores new tile information.

Create an area to store the underlying array using the following strategy:
1. If the added Len < s cap is the cap*2 of the new S
2. If the added Len > s cap is the new s cap = old cap + add data to Len

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.