{"id":96926,"date":"2020-04-29T02:49:21","date_gmt":"2020-04-28T18:49:21","guid":{"rendered":"http:\/\/4563.org\/?p=96926"},"modified":"2020-04-29T02:49:21","modified_gmt":"2020-04-28T18:49:21","slug":"go-%e4%b8%ad-make-%e4%b8%8e-new-%e7%9a%84%e5%8c%ba%e5%88%ab%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=96926","title":{"rendered":"Go \u4e2d make \u4e0e new \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Go \u4e2d make \u4e0e new \u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : w708833018 <\/span>  <span><i><\/i> 50<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u6211\u7406\u89e3\u7684\u662f\uff1a<br \/> &#8211; new \u4f1a\u521d\u59cb\u5316\u503c\u7c7b\u578b\uff08\u5982\u679c int\uff0cstring\uff0cstruct \uff09\uff0c\u5e76\u8fd4\u56de\u6307\u5411\u8be5\u7c7b\u578b\u503c\u7684\u6307\u9488<br \/>&#8211; \uff08 make\/slice\/chan \uff09\u4f7f\u7528 make\uff0cmake \u8fd4\u56de\u7684\u662f\u7c7b\u578b\u672c\u8eab\uff0c\u5f15\u7528\u7c7b\u578b\u6ca1\u5fc5\u8981\u8fd4\u56de\u4ed6\u4eec\u7684\u6307\u9488<\/p>\n<p>\u4f46\u662f\u7f51\u4e0a\u7ecf\u5e38\u51fa\u73b0\u8fd9\u6837\u7684\u89e3\u91ca\uff1a<br \/> &#8211; new \u662f\u7528\u6765\u5206\u914d\u5185\u5b58\u7684\u5185\u5efa\u51fd\u6570\uff0c \u4f46\u4e0e\u5176\u5b83\u8bed\u8a00\u4e2d\u7684\u540c\u540d\u51fd\u6570\u4e0d\u540c\uff0c\u5b83\u4e0d\u4f1a\u201c\u521d\u59cb\u5316\u5185\u5b58\u201d\uff0c\u53ea\u4f1a\u5c06\u201c\u5185\u5b58\u7f6e\u96f6&#8221;<br \/>&#8211; make \u53ea\u7528\u4e8e\u521b\u5efa\u5207\u7247\u3001\u6620\u5c04\u548c\u4fe1\u9053\uff0c\u5e76\u8fd4\u56de\u7c7b\u578b\u4e3a T \uff08\u800c\u975e *T \uff09\u7684\u4e00\u4e2a\u5df2\u521d\u59cb\u5316 \uff08\u800c\u975e\u7f6e\u96f6\uff09\u7684\u503c<\/p>\n<p>\u6211\u4e0d\u660e\u767d\uff0c\u521d\u59cb\u5316\u5185\u5b58\uff0c\u5185\u5b58\u7f6e\u96f6\u6709\u4ec0\u4e48\u533a\u522b\uff0c\u5185\u5b58\u90fd\u7f6e\u96f6\u4e86\uff0c\u96be\u9053\u8fd8\u6ca1\u6709\u521d\u59cb\u5316\u5185\u5b58\u5417      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>13<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"895147\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lhx2008 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             new \u5c31\u53ea\u662f\u5185\u5b58\u5206\u914d\u4e86\uff0cmake \u5c31\u662f\u518d\u505a\u4e2a\u521d\u59cb\u5316\u4e4b\u7c7b\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895148\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lhx2008 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u521d\u59cb\u5316\u6211\u7406\u89e3\u5c31\u662f\u6267\u884c\u4e86\u6784\u9020\u51fd\u6570\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895149\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : noO9LeRxXX <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3e\u4e2a\u4f8b\u5b50\uff0cslice \u8981\u5b58 length \u548c capacity\uff0c\u8fd9\u4e9b\u90fd\u53ef\u4ee5\u4e0d\u4e3a\u96f6\uff0c\u6240\u4ee5\u4e0d\u80fd\u7528 new\u3002\u5177\u4f53 Effective Go \u91cc\u6709\u8bb2\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895150\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : monsterxx03 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             new \u53ea\u662f&amp;T{}\u7684\u4e00\u4e2a\u8bed\u6cd5\u7cd6                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895151\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Cbdy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u57fa\u672c\u6ca1\u6709\u533a\u522b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895152\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ChristopherWu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             * `new` \u4f1a\u7533\u8bf7\u5185\u5b58\u5e76\u5168\u90e8\u6e05 0<br \/>* `make`\u4f1a\u7533\u8bf7\u5185\u5b58\u5e76\u521d\u59cb\u5316\u8be5\u7c7b\u578b<\/p>\n<p>\u50cf `make([]int, 10, 100)` \u8fd9\u79cd\u60c5\u51b5\u5c31\u5fc5\u987b\u8981\u7528`make`\u521d\u59cb\u5316\uff0c\u56e0\u4e3a\u9700\u8981\u521d\u59cb\u5316 `length`, `capacity`<\/p>\n<p>&#8220;`<br \/>var p *[]int = new([]int) \/\/ allocates slice structure; *p == nil; rarely useful<br \/>var v []int = make([]int, 100) \/\/ the slice v now refers to a new array of 100 ints<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895153\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Hellert <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             new \u65b0\u5efa\u4efb\u610f\u7c7b\u578b\u7684\u6307\u9488\u3002<br \/>make \u53ea\u80fd\u7528\u4e8e\u5207\u7247\uff0cmap\uff0c\u901a\u9053\uff0c\u5176\u4ed6\u7c7b\u578b\u662f\u4e0d\u80fd\u7528\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895154\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chitanda <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf7\u53bb\u770b\u4e00\u904d\u5b98\u65b9\u7684 effective go                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895155\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : secondwtq <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u8d77\u6765\u50cf\u662f c++\u7684 new \u548c malloc \u7684\u533a\u522b\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895156\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wweir <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u795e\u7ecf\u75c5\u5f0f\u7684\u9762\u8bd5\u5b98\u559c\u6b22\u95ee\u8fd9\u95ee\u9898\u3002<br \/>\u5b9e\u9645\u6ca1\u5565\u533a\u522b\uff0c\u90fd\u662f\u7533\u8bf7\u5185\u5b58\u3001\u521d\u59cb\u5316\uff0c\u65e0\u975e\u4f5c\u7528\u5bf9\u8c61\u4e0d\u540c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895157\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wweir <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u975e\u8981\u8bf4\u533a\u522b\u7684\u8bdd\uff0cmake \u53ef\u4ee5\u591a\u52a0\u4fe9\u53c2\u6570<br \/>:\u72d7\u5934:                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895158\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lazydog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u66fe\u88ab\u9762\u8bd5\u5b98\u95ee\u5230\u8fc7\u3002\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\uff1amake \u7528\u6765\u521d\u59cb\u5316 Go \u7684\u5185\u90e8\u6570\u636e\u7ed3\u6784\uff0cnew \u7528\u6765\u521b\u5efa\u4e00\u4e2a\u6307\u5411\u8fd4\u56de\u7c7b\u578b\u7684\u6307\u9488\u3002\u6216\u8005\u53c2\u8003\u8fd9\u91cc\uff1a https:\/\/draveness.me\/golang\/docs\/part2-foundation\/ch05-keyword\/golang-make-and-new\/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"895159\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Mithrandir <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf7\u53bb\u770b\u4e00\u904d\u5b98\u65b9\u7684 effective go                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Go \u4e2d make \u4e0e new \u7684&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/96926"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96926"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/96926\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=96926"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=96926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}