{"id":207645,"date":"2025-07-08T10:17:18","date_gmt":"2025-07-08T02:17:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207645\/"},"modified":"2025-07-08T10:17:18","modified_gmt":"2025-07-08T02:17:18","slug":"%e9%80%83%e9%80%b8%e5%88%86%e6%9e%90%e4%b9%8b%e5%89%8d%e5%8f%98%e9%87%8f%e7%9a%84%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f%e6%98%af%e6%80%8e%e6%a0%b7%e7%9a%84%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207645\/","title":{"rendered":"\u9003\u9038\u5206\u6790\u4e4b\u524d\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u662f\u600e\u6837\u7684\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u9003\u9038\u5206\u6790\u4e4b\u524d\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u662f\u600e\u6837\u7684\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-24 11:36:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u9003\u9038\u5206\u6790\u4e4b\u524d\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u662f\u600e\u6837\u7684\uff1f\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u9996\u5148\uff0c\u5982\u679c\u8fd9\u662f\u4e00\u4e2a\u660e\u663e\u6216\u76f4\u63a5\u7684\u7b54\u6848\uff0c\u6211\u6df1\u8868\u6b49\u610f\uff0c\u4f46\u6211\u4f3c\u4e4e\u65e0\u6cd5\u7406\u89e3\u4ee5\u4e0b\u4ee3\u7801\u80cc\u540e\u7684\u786e\u5207\u8fc7\u7a0b\u3002 <\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n)\n\nfunc xyz() *int {\n    n := 42\n    return &amp;n\n}\n\nfunc main() {\n    num := xyz()\n    fmt.Println(\"The number is\", *num)\n}<\/pre>\n<p>\u6211\u7684\u95ee\u9898\u662f\u53d8\u91cf n \u662f\u5426\u5728\u9003\u9038\u5206\u6790\u4e4b\u524d\u5206\u914d\u5230\u5806\u6808\uff0c\u7136\u540e\u4e00\u65e6\u8d85\u51fa\u8303\u56f4\uff0c\u5b83\u662f\u5426\u4f1a\u5728\u5206\u914d\u5230\u5806\u4e4b\u524d\u88ab\u5783\u573e\u6536\u96c6\uff1f\u5f53\u51fd\u6570 xyz \u8fd4\u56de\u65f6\uff0cgolang \u5982\u4f55\u5904\u7406\u6307\u9488\uff1f\u6211\u8981\u6c42\u63d0\u4f9b\u4e00\u4e9b\u6280\u672f\u6027\u7684\u5206\u6b65\u6d41\u7a0b\uff0c\u540c\u65f6\u4e5f\u4e3a\u4e86\u6d88\u9664\u4efb\u4f55\u77e5\u8bc6\u5dee\u8ddd\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u8f6c\u4e49\u5206\u6790\u5728\u7f16\u8bd1\u65f6\u8fdb\u884c\u3002\u5f53\u7f16\u8bd1\u5668\u610f\u8bc6\u5230\u53d8\u91cf <code>n<\/code> \u7684\u5730\u5740\u79bb\u5f00\u51fd\u6570\u65f6\uff0c\u5b83\u4f1a\u7f16\u8bd1\u4e00\u4e2a\u5982\u4e0b\u6240\u793a\u7684\u51fd\u6570\uff1a<\/p>\n<pre>func xyz() *int {\n    n:=newInHeap(int)\n    *n := 42\n    return n\n}<\/pre>\n<p>\u8fd9\u91cc\uff0c<code>newinheap<\/code> \u662f\u4e00\u4e2a\u5047\u8bbe\u51fd\u6570\uff0c\u5b83\u603b\u662f\u5728\u5806\u4e2d\u5206\u914d\u53d8\u91cf\u3002\u5982\u679c\u53d8\u91cf\u6ca1\u6709\u8f6c\u4e49\u51fd\u6570\uff0c\u5219\u5e38\u89c4 <code>new<\/code> \u53ef\u80fd\u4f1a\u5728\u5806\u6808\u4e0a\u5206\u914d\u53d8\u91cf\u3002 <\/p>\n<p>\u8fd4\u56de\u6307\u9488\u7684\u751f\u547d\u5468\u671f\u5728\u8fd0\u884c\u65f6\u7531\u5e38\u89c4 gc \u89c4\u5219\u63a7\u5236\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u9003\u9038\u5206\u6790\u4e4b\u524d\u53d8\u91cf\u7684\u751f\u547d\u5468\u671f\u662f\u600e\u6837\u7684\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207645","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207645"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207645\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}