{"id":208062,"date":"2025-07-08T08:54:51","date_gmt":"2025-07-08T00:54:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/208062\/"},"modified":"2025-07-08T08:54:51","modified_gmt":"2025-07-08T00:54:51","slug":"%e5%a6%82%e4%bd%95%e8%ae%a1%e7%ae%97%e5%a4%8d%e6%9d%82%e6%98%a0%e5%b0%84%e5%8f%98%e9%87%8f%e7%9a%84%e5%86%85%e5%ad%98%e5%a4%a7%e5%b0%8f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208062\/","title":{"rendered":"\u5982\u4f55\u8ba1\u7b97\u590d\u6742\u6620\u5c04\u53d8\u91cf\u7684\u5185\u5b58\u5927\u5c0f"},"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>\u5982\u4f55\u8ba1\u7b97\u590d\u6742\u6620\u5c04\u53d8\u91cf\u7684\u5185\u5b58\u5927\u5c0f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-28 14:00:32<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u8ba1\u7b97\u590d\u6742\u6620\u5c04\u53d8\u91cf\u7684\u5185\u5b58\u5927\u5c0f\u300b<\/span>\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6b63\u5728\u5c1d\u8bd5\u8ba1\u7b97\u5185\u5b58\u4e2d\u53d8\u91cf\uff08entrymap\uff09\u7684\u5927\u5c0f\u3002<\/p>\n<pre>type entry interface {\n    a() string\n    b() string\n    c() time.time\n    d() int64\n}\n\ntype entries []entry\ntype entrymap map[string]entries<\/pre>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\u6211\u5f97\u5230\u7684\u662f\uff1a<\/p>\n<pre>hm = make(EntryMap)\nSizeInMem = 8 \/\/Length of Empty HMap\n\nfor key, value := range hm {\n    A = 8 \/\/ For each Key Value Assignment\n    B = len(Key) + 1 \/\/ Size of key string var\n    C = len(Entries) * unsafe.Sizeof(Entry) \/\/ Size of Entry object * len of slice\n    SizeInMem += A+B+C\n}\n\nfmt.Println(\"Size in Memory &amp;v\", SizeInMem)<\/pre>\n<p>\u8fd9\u662f\u786e\u5b9a\u5185\u5b58\u4e2d\u53d8\u91cf\u5927\u5c0f\u7684\u6b63\u786e\u65b9\u6cd5\u5417\uff1f<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u8fd9\u4e0d\u662f\u4f60\u53ef\u4ee5\u53ca\u65f6\u8ba1\u7b97\u7684\u4e8b\u60c5&#8230;&#8230;<\/p>\n<p>\u4f46\u662f\u6211\u4e3a\u4f60\u51c6\u5907\u4e86\u6d4b\u8bd5\u6f14\u793a\u3002<\/p>\n<\/p>\n<pre>\ntype Entry interface {\n    A() string\n    B() string\n    D() int64\n}\n\ntype Entries []Entry\ntype EntryMap map[string]Entries\n\nfunc main() {\n\n    size := memcalc(func() {\n        \/* Put your code here *\/\n        var hm = make(EntryMap)\n\n        \/\/ do something with map, grow, for example        \n\n        \/\/ pass variable to this function to measure\n        calc(hm)\n    })\n\n    fmt.Println(size)\n}\n<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/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-208062","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208062","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=208062"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208062\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}