{"id":361,"date":"2018-09-04T21:51:40","date_gmt":"2018-09-04T13:51:40","guid":{"rendered":"https:\/\/www.myway5.com\/?p=361"},"modified":"2023-07-05T21:46:00","modified_gmt":"2023-07-05T13:46:00","slug":"go-memory","status":"publish","type":"post","link":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/","title":{"rendered":"go \u5185\u5b58\u6a21\u578b"},"content":{"rendered":"<h2>\u7b80\u4ecb<\/h2>\n<p>go\u7684\u5185\u5b58\u6a21\u578b\u65e8\u5728\u8bf4\u660e\uff1a\u4e00\u4e2a\u534f\u7a0b\u4e2d\u5bf9\u53d8\u91cfv\u7684\u5199\u5165\u4ea7\u751f\u7684\u503c\u53ef\u4ee5\u4fdd\u8bc1\u88ab\u53e6\u4e00\u4e2a\u534f\u7a0b\u4e2d\u7684\u5bf9\u53d8\u91cfv\u7684\u8bfb\u53d6\u89c2\u5bdf\u5230\u3002<\/p>\n<h2>Happens Before<\/h2>\n<p>\u5728\u4e00\u4e2a\u534f\u7a0b\u5185\uff0c\u8bfb\u5199\u64cd\u4f5c\u5fc5\u987b\u6309\u7167\u7a0b\u5e8f\u6307\u5b9a\u7684\u987a\u5e8f\u8fdb\u884c\u3002\u5728\u4e00\u4e2a\u534f\u7a0b\u5185\uff0c\u7f16\u8bd1\u5668\u548c\u5904\u7406\u5668\u53ef\u80fd\u5bf9\u8bfb\u5199\u64cd\u4f5c\u91cd\u5199\u6392\u5e8f\uff0c\u4f46\u662f\u8fd9\u4e2a\u6392\u5e8f\u7684\u524d\u63d0\u662f\uff1a\u5728<code>\u5f53\u524d\u534f\u7a0b<\/code>\u5185\uff0c\u4e0d\u4f1a\u6539\u53d8\u7a0b\u5e8f\u7684\u6267\u884c\u884c\u4e3a\u3002\u4f46\u662f\u8fd9\u4e2a\u91cd\u65b0\u6392\u5e8f\u662f\u4e0d\u4fdd\u8bc1\u5176\u4ed6\u534f\u7a0b\u89c2\u6d4b\u5230\u6267\u884c\u987a\u5e8f\u662f\u4e0d\u6539\u53d8\u7684\u3002\u6bd4\u5982\u5728\u534f\u7a0b1\u4e2d<code>a=1;b=2<\/code>\uff0c\u4f46\u5728\u5176\u4ed6\u534f\u7a0b\u7684\u611f\u77e5\u4e2d\uff0c\u53ef\u80fdb\u6bd4a\u5148\u66f4\u65b0\u503c\u3002<\/p>\n<p>\u6211\u4eec\u8fd9\u91cc\u5b9a\u4e49<code>Happens Before(\u5728...\u4e4b\u524d\u53d1\u751f)<\/code>\uff0c\u5982\u679c\u4e8b\u4ef6e1\u5728\u4e8b\u4ef6e2<code>\u4e4b\u524d\u53d1\u751f<\/code>\uff0c\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u8bf4e2\u5728e1\u4e4b\u540e\u53d1\u751f\u3002\u5982\u679ce1\u65e2\u4e0d\u5728e2\u4e4b\u524d\u53d1\u751f\uff0c\u4e5f\u4e0d\u5728e2\u4e4b\u540e\u53d1\u751f\u3002\u90a3\u4e48e1\u548ce2\u5c31\u662f\u540c\u65f6\u53d1\u751f\u7684\uff08\u5e76\u53d1\uff09\u3002<\/p>\n<p>\u5728\u4e00\u4e2a\u534f\u7a0b\u5185\uff0c<code>Happens Before<\/code>\u7684\u987a\u5e8f\u5c31\u662f\u7a0b\u5e8f\u8868\u8fbe\u7684\u90a3\u6837\u3002<\/p>\n<p>\u5982\u679c\u4e0b\u9762\u4e24\u70b9\u53ef\u4ee5\u4fdd\u8bc1\uff0c\u5c31\u8bf4\u660e\u5bf9\u53d8\u91cfv\u7684\u8bfb\u53d6r<code>\u5141\u8bb8<\/code>\u89c2\u5bdf\u5230\u5bf9\u53d8\u91cfv\u7684\u5199\u5165w\uff1a<\/p>\n<ul>\n<li>r\u4e0d\u662f\u5728w\u4e4b\u524d\u53d1\u751f<\/li>\n<li>\u5728w\u4e4b\u540e\u5e76\u4e14r\u4e4b\u524d\u6ca1\u6709\u5176\u4ed6\u7684\u5bf9v\u7684\u5199\u5165w&#8217;<\/li>\n<\/ul>\n<p>\u4e3a\u4e86\u4fdd\u8bc1\u53d8\u91cfv\u7684\u8bfb\u53d6r\u89c2\u5bdf\u5230v\u7684\u7279\u5b9a\u5199\u5165w\uff0c\u5e76\u4e14\u4fdd\u8bc1w\u662f\u552f\u4e00\u5141\u8bb8\u88abr\u89c2\u5bdf\u5230\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cr\u4fdd\u8bc1\u80fd\u89c2\u5bdf\u5230w\u3002\u9700\u8981\u505a\u5230\u4e0b\u9762\u4e24\u70b9\uff1a<\/p>\n<ul>\n<li>w\u5728r\u4e4b\u524d\u53d1\u751f<\/li>\n<li>\u5176\u4ed6\u7684\u5bf9v\u7684\u5199\u5165w&#8217;\u8981\u4e48\u53d1\u751f\u5728w\u4e4b\u524d\uff0c\u8981\u4e48\u53d1\u751f\u5728w\u4e4b\u540e<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u4e24\u70b9\u6bd4\u4e0a\u9762\u4e24\u70b9\u8981\u6c42\u66f4\u4e3a\u4e25\u683c\u3002\u5b83\u4fdd\u8bc1\u4e86\u6ca1\u6709\u5176\u4ed6\u7684\u5199\u5165w&#8217;\u548cw\u3001r\u540c\u65f6\u53d1\u751f\u3002<\/p>\n<p>\u5728\u4e00\u4e2a\u534f\u7a0b\u5185\uff0c\u56e0\u4e3a\u6ca1\u6709\u5e76\u53d1\uff0c\u6240\u4ee5\u8fd9\u4e24\u79cd\u5b9a\u4e49\u662f\u4e00\u81f4\u7684\uff1a\u8bfb\u53d6r\u53ef\u4ee5\u89c2\u5bdf\u5230\u5199\u5165w\u5bf9\u53d8\u91cfv\u6700\u8fd1\u4e00\u6b21\u7684\u5199\u5165\u3002\u4f46\u662f\u5f53\u591a\u4e2a\u534f\u7a0b\u540c\u65f6\u8bbf\u95ee\u540c\u4e00\u4e2a\u5171\u4eab\u53d8\u91cf\u65f6\uff0c\u5c31\u5fc5\u987b\u4f7f\u7528\u540c\u6b65\u4e8b\u4ef6\u6765\u5efa\u7acb<code>Happens Before<\/code>\u8bed\u4e49\u6765\u4fdd\u8bc1\u8bfb\u53d6r\u53ef\u4ee5\u89c2\u5bdf\u5230\u6307\u5b9a\u7684\u5199\u5165w\u3002<\/p>\n<p>\u5728\u5185\u5b58\u6a21\u578b\u4e2d\uff0c\u5bf9\u53d8\u91cfv\u4ee50\u503c\u521d\u59cb\u5316\u662f\u4e00\u6b21\u5199\u5165\u3002<\/p>\n<p>\u5bf9\u4e8e\u5927\u4e8e\u5355\u673a\u5668\u5b57\u8282\u7684\u8bfb\u53d6\u548c\u5199\u5165\uff0c\u53ef\u4ee5\u770b\u505a\u662f\u5bf9\u591a\u4e2a\u5355\u673a\u5668\u5b57\u8282\u7684\u4e71\u5e8f\u64cd\u4f5c\u3002<\/p>\n<h2>\u540c\u6b65<\/h2>\n<h3>\u521d\u59cb\u5316<\/h3>\n<p>\u7a0b\u5e8f\u521d\u59cb\u5316\u662f\u5728\u5355\u534f\u7a0b\u5185\u8fd0\u884c\u7684\uff0c\u4f46\u662f\u8fd9\u4e2a\u534f\u7a0b\u53ef\u80fd\u521b\u5efa\u5176\u4ed6\u7684\u534f\u7a0b\u3002\u5b83\u4eec\u662f\u5e76\u53d1\u7684\u3002<\/p>\n<p>\u5982\u679c\u5305p\u5f15\u5165\u4e86\u5305q\uff0c\u5219q\u7684\u521d\u59cb\u5316\u51fd\u6570\u4f1a\u5728p\u7684\u521d\u59cb\u5316\u51fd\u6570\u4e4b\u524d\u8fd0\u884c\u3002<\/p>\n<p>main.main\u51fd\u6570\u5728\u6240\u6709\u7684\u521d\u59cb\u5316\u51fd\u6570\u4e4b\u540e\u8fd0\u884c\u3002<\/p>\n<h3>\u534f\u7a0b\u521b\u5efa<\/h3>\n<p><code>go<\/code>\u5173\u952e\u5b57\u521b\u5efa\u534f\u7a0b\u53d1\u751f\u5728\u534f\u7a0b\u8fd0\u884c\u4e4b\u524d\u3002<\/p>\n<h3>\u534f\u7a0b\u9500\u6bc1<\/h3>\n<p>\u534f\u7a0b\u7684\u9500\u6bc1\u4e0d\u4fdd\u8bc1\u5728\u7a0b\u5e8f\u4e2d\u7684\u4efb\u4f55\u4e8b\u4ef6\u53d1\u751f\u4e4b\u524d\u3002\u6bd4\u5982\uff1a<\/p>\n<pre><code class=\"line-numbers\">var a string\n\nfunc hello() {\n    go func() { a = \"hello\" }()\n    print(a)\n}\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u8d4b\u503c\u6ca1\u6709\u8ddf\u968f\u4efb\u4f55\u540c\u6b65\u4e8b\u4ef6\uff0c\u6240\u4ee5\u5b83\u4e0d\u4fdd\u8bc1\u88ab\u5176\u4ed6\u534f\u7a0b\u89c2\u5bdf\u5230\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6fc0\u8fdb\u7684\u7f16\u8bd1\u5668\u4f1a\u5220\u9664\u6574\u4e2ago\u8bed\u53e5\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\uff0c\u53ef\u4ee5\u4f7f\u7528\u540c\u6b65\u539f\u8bed\u6bd4\u5982<code>\u9501<\/code>\u6216<code>\u7ba1\u9053\u901a\u4fe1<\/code>\u6765\u5efa\u7acb\u4e00\u4e2a\u76f8\u5173\u7684\u6267\u884c\u987a\u5e8f\u3002<\/p>\n<h3>\u7ba1\u9053\u901a\u4fe1<\/h3>\n<p>\u5728go\u7684\u534f\u7a0b\u4e2d\uff0c\u7ba1\u9053\u901a\u4fe1\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u540c\u6b65\u65b9\u6cd5\u3002\u901a\u5e38\u53d1\u9001\u65b9\u548c\u63a5\u53d7\u65b9\u5728\u4e24\u4e2a\u4e0d\u540c\u7684\u534f\u7a0b\u4e2d\uff0c\u5229\u7528\u53d1\u9001\u548c\u63a5\u6536\u8fd9\u4e24\u4e2a\u6709\u5e8f\u7684\u52a8\u4f5c\u6765\u8fdb\u884c\u540c\u6b65\u3002<\/p>\n<blockquote><p>\n  1.\u5728\u6709\u7f13\u51b2\u7684\u7ba1\u9053\u4e2d\uff0c\u53d1\u9001\u4e00\u5b9a\u53d1\u751f\u5728\u63a5\u6536\u5b8c\u6210\u524d\u3002(A send on a channel happens before the corresponding receive from that channel completes.\n<\/p><\/blockquote>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"line-numbers\">var c = make(chan int, 10)\nvar a string\n\nfunc f() {\n    a = \"hello, world\"\n    c &lt;- 0\n}\n\nfunc main() {\n    go f()\n    &lt;-c\n    print(a)\n}\n<\/code><\/pre>\n<p><code>a = \"hello, world\"<\/code>\u4e00\u5b9a\u5728<code>c&lt;-0<\/code>\u4e4b\u524d\u53d1\u751f\uff0c<code>c&lt;-0<\/code>\u4e00\u5b9a\u5728<code>&lt;-c<\/code>\u4e4b\u524d\u53d1\u751f\uff0c<code>&lt;-c<\/code>\u4e00\u5b9a\u5728<code>print(a)<\/code>\u4e4b\u524d\u53d1\u751f\u3002\u8fd9\u6837\u5c31\u80fd\u4fdd\u8bc1<code>a = \"hello, world\"<\/code>\u5728<code>print(a)<\/code>\u4e4b\u524d\u53d1\u751f\u3002\u5219\u4fdd\u8bc1\u53ef\u4ee5\u6253\u5370\u51fa<code>hello, world<\/code>\u3002<\/p>\n<blockquote><p>\n  2.\u7ba1\u9053\u7684\u5173\u95ed\u4e00\u5b9a\u53d1\u751f\u5728\u4ece\u7ba1\u9053\u4e2d\u63a5\u6536\u503c\u4e4b\u524d\u3002\n<\/p><\/blockquote>\n<p>\u56e0\u6b64\u4e0a\u9762\u7684\u4f8b\u5b50\u5c06<code>&lt;-c<\/code>\u66ff\u6362\u6210<code>close(c)<\/code>\u4e5f\u662f\u53ef\u4ee5\u7684\u3002<\/p>\n<blockquote><p>\n  3.\u5728\u65e0\u7f13\u51b2\u7ba1\u9053\u4e2d\uff0c\u63a5\u6536\u4e00\u5b9a\u53d1\u751f\u5728\u53d1\u9001\u5b8c\u6210\u524d\u3002(The closing of a channel happens before a receive that returns a zero value because the channel is closed.)\n<\/p><\/blockquote>\n<p>\u4f8b\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\u5c06\u53d1\u9001\u548c\u63a5\u6536\u8bed\u53e5\u4e92\u6362\u4e86\u4f4d\u7f6e\u3002<\/p>\n<pre><code class=\"line-numbers\">var c = make(chan int)\nvar a string\n\nfunc f() {\n    a = \"hello, world\"\n    &lt;-c\n}\nfunc main() {\n    go f()\n    c &lt;- 0\n    print(a)\n}\n<\/code><\/pre>\n<p>\u5982\u679c\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\u7ba1\u9053\u662f\u6709\u7f13\u51b2\u7684(e.g., c = make(chan int, 1)) \uff0c\u5c31\u65e0\u6cd5\u4fdd\u8bc1\u4e00\u5b9a\u80fd\u6253\u5370\u51fa<code>hello,world<\/code><\/p>\n<blockquote><p>\n  4.\u5728\u5bb9\u91cf\u4e3aC\u7684\u7ba1\u9053\u4e2d\uff0c\u7b2ck\u4e2a\u63a5\u6536\u53d1\u751f\u5728k+C\u4e2a\u53d1\u9001\u5b8c\u6210\u4e4b\u524d\u3002(The kth receive on a channel with capacity C happens before the k+Cth send from that channel completes.)\n<\/p><\/blockquote>\n<p>\u7b2c4\u70b9\u63a8\u5e7f\u4e86\u7b2c\u4e00\u70b9\u7684\u89c4\u5219\u3002\u8fd9\u91cc\u5176\u5b9e\u6709\u4e00\u70b9\u7ed5\uff0c\u4e3e\u4e2a\u4f8b\u5b50\uff1a<code>\u7b2c1\u4e2a\u63a5\u6536\u53d1\u751f\u57281+C\u4e2a\u53d1\u9001\u5b8c\u6210\u4e4b\u524d<\/code>\u3002\u9996\u5148\u601d\u8003\uff1a\u7b2c\u4e00\u4e2a\u63a5\u6536\u80fd\u5426\u4fdd\u8bc1\u57280+C\u4e2a\u53d1\u9001\u5b8c\u6210\u4e4b\u524d\uff1f\u7b54\u6848\u662f\u4e0d\u80fd\u3002\u56e0\u4e3a\u7ba1\u9053\u6709C\u4e2a\u5bb9\u91cf\u7684\u7f13\u51b2\uff0cC\u4e2a\u53d1\u9001\u8bed\u53e5\u53d1\u9001\u5b8c\u6210\u524d\uff0c\u5b8c\u5168\u53ef\u4ee5\u4e0d\u8c03\u7528\u63a5\u6536\u8bed\u53e5\u3002\u90a3<code>\u7b2c1\u4e2a\u63a5\u6536\u53d1\u751f\u57281+C\u4e2a\u53d1\u9001\u5b8c\u6210\u4e4b\u524d<\/code>\u5982\u4f55\u4fdd\u8bc1\uff0c\u6211\u4eec\u77e5\u9053\uff0c\u5f53\u7ba1\u9053\u7f13\u51b2\u6ee1\u4e86\u4e4b\u540e\uff0c\u5c31\u65e0\u6cd5\u5411\u7ba1\u9053\u4e2d\u53d1\u9001\uff0c\u53d1\u9001\u8bed\u53e5\u4f1a\u963b\u585e\u3002\u56e0\u6b64\u5fc5\u987b\u5728\u63a5\u6536\u4e4b\u540e\u53d1\u9001\u8bed\u53e5\u624d\u80fd\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n<p>\u7b2c\u56db\u70b9\u89c4\u5219\u4f7f\u5f97<code>\u8ba1\u6570\u4fe1\u53f7\u91cf\u53ef\u4ee5\u7531\u7f13\u51b2\u7ba1\u9053\u5efa\u6a21<\/code>\uff1a\u7ba1\u9053\u4e2d\u7684\u6570\u91cf\u5bf9\u5e94\u4e86\u5f53\u524d\u5e76\u53d1\u91cf\uff0c\u7ba1\u9053\u7684\u5bb9\u91cf\u5bf9\u5e94\u4e86\u6700\u5927\u5e76\u53d1\u91cf\u3002\u53d1\u9001\u8bed\u53e5\u5360\u7528\u4e00\u4e2a\u4fe1\u7528\u91cf\uff0c\u63a5\u6536\u8bed\u53e5\u91ca\u653e\u4e00\u4e2a\u4fe1\u53f7\u91cf\u3002\u8fd9\u662f\u9650\u5236\u5e76\u53d1\u91cf\u7684\u4e00\u4e2a\u60ef\u7528\u624b\u6bb5\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u9650\u5236\u4e86\u6700\u5927\u5e76\u53d1\u91cf\u4e3a3\uff1a<\/p>\n<pre><code class=\"line-numbers\">var limit = make(chan int, 3)\n\nfunc main() {\n    for _, w := range work {\n        go func(w func()) {\n            limit &lt;- 1\n            w()\n            &lt;-limit\n        }(w)\n    }\n    select{}\n}\n<\/code><\/pre>\n<p>\u540c\u6837\u7684\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u7528lock\u548conce\u6765\u5b9e\u73b0<code>happens before<\/code>\u8bed\u4e49<\/p>\n<h2>\u4e0d\u6b63\u786e\u7684\u540c\u6b65\u65b9\u5f0f<\/h2>\n<p>\u5373\u4f7f\u8bfbr\u53ef\u4ee5\u89c2\u5bdf\u5230\u540c\u65f6\u53d1\u751f\u7684\u5199w\u7684\u503c\uff0c\u4f46\u8fd9\u5e76\u4e0d\u610f\u5473\u8fd9\u5728r\u4e4b\u540e\u53d1\u751f\u7684\u8bfbr&#8217;\u53ef\u4ee5\u89c2\u5bdf\u5230\u5728w\u4e4b\u524d\u53d1\u751f\u7684\u5199w&#8217;\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"line-numbers\">var a, b int\n\nfunc f() {\n    a = 1\n    b = 2\n}\n\nfunc g() {\n    print(b)\n    print(a)\n}\n\nfunc main() {\n    go f()\n    g()\n}\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u7a0b\u5e8f\u53ef\u80fd\u6253\u5370\u51fa2\u30010<\/p>\n<p>\u8fd9\u79cd\u73b0\u8c61\u4f7f\u5f97\u4e00\u4e9b\u5e38\u89c1\u7684\u65b9\u5f0f\u5931\u6548\u3002\u6bd4\u5982<code>\u53cc\u91cd\u9501\u5b9a\u68c0\u67e5<\/code><\/p>\n<pre><code class=\"line-numbers\">var a string\nvar done bool\n\nfunc setup() {\n    a = \"hello, world\"\n    done = true\n}\n\nfunc doprint() {\n    if !done {\n        once.Do(setup)\n    }\n    print(a)\n}\n\nfunc twoprint() {\n    go doprint()\n    go doprint()\n}\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u7a0b\u5e8f\u4e0d\u80fd\u4fdd\u8bc1<code>print(a)<\/code>\u65f6\u80fd\u591f\u89c2\u5bdf\u5230a\u7684\u503c\u4e00\u5b9a\u662f<code>hello, world<\/code>\u3002<\/p>\n<p>\u540c\u6837\u7684\uff0c\u8fd8\u6709\u4e00\u79cd\u5faa\u73af\u7b49\u5f85\u7684\u5199\u6cd5\u4e5f\u53ef\u80fd\u6709\u95ee\u9898\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"line-numbers\">var a string\nvar done bool\n\nfunc setup() {\n    a = \"hello, world\"\n    done = true\n}\n\nfunc main() {\n    go setup()\n    for !done {\n    }\n    print(a)\n}\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u7a0b\u5e8f\u4e5f\u4e0d\u4fdd\u8bc1<code>print(a)<\/code>\u4e00\u5b9a\u80fd\u6253\u5370\u51fa\u5185\u5bb9\uff0c\u751a\u81f3\u66f4\u574f\u7684\u60c5\u51b5\u4e0b\u65e0\u6cd5\u89c2\u5bdf\u5230<code>done<\/code>\u53d1\u751f<br \/>\n\u4e86\u6539\u53d8\uff0c\u56e0\u6b64\u7a0b\u5e8f\u4f1a\u6b7b\u5faa\u73af\u4e0b\u53bb\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u884d\u751f\u7248\u672c\u7684\u5199\u6cd5\u4e5f\u4f1a\u6709\u95ee\u9898<\/p>\n<pre><code class=\"line-numbers\">type T struct {\n    msg string\n}\n\nvar g *T\n\nfunc setup() {\n    t := new(T)\n    t.msg = \"hello, world\"\n    g = t\n}\n\nfunc main() {\n    go setup()\n    for g == nil {\n    }\n    print(g.msg)\n}\n<\/code><\/pre>\n<p>\u5373\u4f7f<code>main<\/code>\u534f\u7a0b\u89c2\u5bdf\u5230\u4e86g\u88ab\u8d4b\u503c\uff0c\u4e5f\u4e0d\u4e00\u5b9a\u80fd\u89c2\u5bdf\u5230<code>g.msg<\/code>\u6709\u503c\u3002<\/p>\n<h2>\u53c2\u8003<\/h2>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/golang.org\/ref\/mem\">The Go Memory Model\uff08\u539f\u6587\uff09<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb go\u7684\u5185\u5b58\u6a21\u578b\u65e8\u5728\u8bf4\u660e\uff1a\u4e00\u4e2a\u534f\u7a0b\u4e2d\u5bf9\u53d8\u91cfv\u7684\u5199\u5165\u4ea7\u751f\u7684\u503c\u53ef\u4ee5\u4fdd\u8bc1\u88ab\u53e6\u4e00\u4e2a\u534f\u7a0b\u4e2d\u7684\u5bf9\u53d8\u91cfv\u7684\u8bfb\u53d6\u89c2\u5bdf\u5230\u3002  &hellip; <a href=\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">go \u5185\u5b58\u6a21\u578b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[68],"class_list":["post-361","post","type-post","status-publish","format-standard","hentry","category-go","tag-gomemory"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>go \u5185\u5b58\u6a21\u578b - \u4e00\u53ea\u5b89\u9759\u7684\u732b<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"go \u5185\u5b58\u6a21\u578b - \u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"og:description\" content=\"\u7b80\u4ecb go\u7684\u5185\u5b58\u6a21\u578b\u65e8\u5728\u8bf4\u660e\uff1a\u4e00\u4e2a\u534f\u7a0b\u4e2d\u5bf9\u53d8\u91cfv\u7684\u5199\u5165\u4ea7\u751f\u7684\u503c\u53ef\u4ee5\u4fdd\u8bc1\u88ab\u53e6\u4e00\u4e2a\u534f\u7a0b\u4e2d\u7684\u5bf9\u53d8\u91cfv\u7684\u8bfb\u53d6\u89c2\u5bdf\u5230\u3002 &hellip; \u7ee7\u7eed\u9605\u8bfbgo \u5185\u5b58\u6a21\u578b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\" \/>\n<meta property=\"og:site_name\" content=\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-04T13:51:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-05T13:46:00+00:00\" \/>\n<meta name=\"author\" content=\"jiangpengfei\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"jiangpengfei\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\"},\"author\":{\"name\":\"jiangpengfei\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"headline\":\"go \u5185\u5b58\u6a21\u578b\",\"datePublished\":\"2018-09-04T13:51:40+00:00\",\"dateModified\":\"2023-07-05T13:46:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\"},\"wordCount\":137,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"keywords\":[\"go\u5185\u5b58\u6a21\u578b\"],\"articleSection\":[\"go\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\",\"url\":\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\",\"name\":\"go \u5185\u5b58\u6a21\u578b - \u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/#website\"},\"datePublished\":\"2018-09-04T13:51:40+00:00\",\"dateModified\":\"2023-07-05T13:46:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.myway5.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"go \u5185\u5b58\u6a21\u578b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.myway5.com\/#website\",\"url\":\"https:\/\/www.myway5.com\/\",\"name\":\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"description\":\"\u60f3\u5565\u5462\",\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.myway5.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\",\"name\":\"jiangpengfei\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"caption\":\"jiangpengfei\"},\"logo\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.myway5.com\/index.php\/author\/joyme\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"go \u5185\u5b58\u6a21\u578b - \u4e00\u53ea\u5b89\u9759\u7684\u732b","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/","og_locale":"zh_CN","og_type":"article","og_title":"go \u5185\u5b58\u6a21\u578b - \u4e00\u53ea\u5b89\u9759\u7684\u732b","og_description":"\u7b80\u4ecb go\u7684\u5185\u5b58\u6a21\u578b\u65e8\u5728\u8bf4\u660e\uff1a\u4e00\u4e2a\u534f\u7a0b\u4e2d\u5bf9\u53d8\u91cfv\u7684\u5199\u5165\u4ea7\u751f\u7684\u503c\u53ef\u4ee5\u4fdd\u8bc1\u88ab\u53e6\u4e00\u4e2a\u534f\u7a0b\u4e2d\u7684\u5bf9\u53d8\u91cfv\u7684\u8bfb\u53d6\u89c2\u5bdf\u5230\u3002 &hellip; \u7ee7\u7eed\u9605\u8bfbgo \u5185\u5b58\u6a21\u578b","og_url":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/","og_site_name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","article_published_time":"2018-09-04T13:51:40+00:00","article_modified_time":"2023-07-05T13:46:00+00:00","author":"jiangpengfei","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"jiangpengfei","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#article","isPartOf":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/"},"author":{"name":"jiangpengfei","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"headline":"go \u5185\u5b58\u6a21\u578b","datePublished":"2018-09-04T13:51:40+00:00","dateModified":"2023-07-05T13:46:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/"},"wordCount":137,"commentCount":0,"publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"keywords":["go\u5185\u5b58\u6a21\u578b"],"articleSection":["go"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/","url":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/","name":"go \u5185\u5b58\u6a21\u578b - \u4e00\u53ea\u5b89\u9759\u7684\u732b","isPartOf":{"@id":"https:\/\/www.myway5.com\/#website"},"datePublished":"2018-09-04T13:51:40+00:00","dateModified":"2023-07-05T13:46:00+00:00","breadcrumb":{"@id":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.myway5.com\/index.php\/2018\/09\/04\/go-memory\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.myway5.com\/"},{"@type":"ListItem","position":2,"name":"go \u5185\u5b58\u6a21\u578b"}]},{"@type":"WebSite","@id":"https:\/\/www.myway5.com\/#website","url":"https:\/\/www.myway5.com\/","name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","description":"\u60f3\u5565\u5462","publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.myway5.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685","name":"jiangpengfei","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","caption":"jiangpengfei"},"logo":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/"},"url":"https:\/\/www.myway5.com\/index.php\/author\/joyme\/"}]}},"views":5949,"_links":{"self":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/comments?post=361"}],"version-history":[{"count":2,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/361\/revisions"}],"predecessor-version":[{"id":1584,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/361\/revisions\/1584"}],"wp:attachment":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/media?parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/categories?post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/tags?post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}