Go language memory allocation mechanism

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

This article is to learn <<go language programming >>--Tsinghua University Press (Wang Peng authored) January 2014 first edition of some notes, if there is infringement, please inform the author, will be deleted within 24 hours, reproduced please indicate the source!

The go language has two memory allocation mechanisms, namely the built-in function new () and make ().

-New ()

-Definition: Func new (type) * Type

-The return value is a memory block pointer

-New () is a built-in function that differs from the new operator in other languages, and it only zeros the memory instead of initializing the memory.

-Make ()

-Definition: Func make (type, size Integertype) Type

-When the Make () function is called, the type must be a reference type (Slice, Map, or Channel), Integertype specifies the number of objects to be created.

-Make () The return value is an object, not a memory space pointer returned by new.

-Make vs. new

var p * []intnew([]int)var v []int = make ([]int , 10)

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.