<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                36. #### Go中new和make的區別在Go中,的值類型和引用類型: ~~~gfm 值類型:int,float,bool,string,struct和array. 變量直接存儲值,分配棧區的內存空間,這些變量所占據的空間在函數被調用完后會自動釋放。 引用類型:slice,map,chan和值類型對應的指針. 變量存儲的是一個地址(或者理解為指針),指針指向內存中真正存儲數據的首地址。內存通常在堆上分配,通過GC回收。 ~~~ 這里需要注意的是: 對于引用類型的變量,我們不僅要聲明變量,更重要的是,我們得手動為它分配空間. 因此new該方法的參數要求傳入一個類型,而不是一個值,它會申請一個該類型大小的內存空間,并會初始化為對應的零值,返回指向該內存空間的一個指針。 ~~~go // The new built-in function allocates memory. The first argument is a type, // not a value, and the value returned is a pointer to a newly // allocated zero value of that type. func new(Type) *Type ~~~ 而make也是用于內存分配,但是和new不同,只用來引用對象slice、map和channel的內存創建,它返回的類型就是類型本身,而不是它們的指針類型。 make(\[\]int, 2, 4) 第三種用法,第二參數指定的是切片的長度,第三個參數是用來指定預留的空間長度,例如a := make(\[\]int, 2, 4), 這里值得注意的是返回的切片a的總長度是4,預留的意思并不是另外多出來4的長度,其實是包含了前面2個已經切片的個數的。所以舉個例子當你這樣用的時候 a := make(\[\]int, 4, 2),就會報語法錯誤。 ~~~ // The make built-in function allocates and initializes an object of type // slice, map, or chan (only). Like new, the first argument is a type, not a // value. Unlike new, make's return type is the same as the type of its // argument, not a pointer to it. The specification of the result depends on // the type: // Slice: The size specifies the length. The capacity of the slice is // equal to its length. A second integer argument may be provided to // specify a different capacity; it must be no smaller than the // length. For example, make([]int, 0, 10) allocates an underlying array // of size 10 and returns a slice of length 0 and capacity 10 that is // backed by this underlying array. // Map: An empty map is allocated with enough space to hold the // specified number of elements. The size may be omitted, in which case // a small starting size is allocated. // Channel: The channel's buffer is initialized with the specified // buffer capacity. If zero, or the size is omitted, the channel is // unbuffered. func make(t Type, size ...IntegerType) Type ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看