{"id":320,"date":"2023-09-16T10:32:10","date_gmt":"2023-09-16T02:32:10","guid":{"rendered":""},"modified":"2023-09-18T11:49:45","modified_gmt":"2023-09-18T03:49:45","slug":"c%e8%af%ad%e8%a8%80%e6%95%b0%e7%bb%84%e5%88%9d%e5%a7%8b%e5%8c%96%e7%9a%84%e4%b8%89%e7%a7%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/mushiming.com\/320.html","title":{"rendered":"C\u8bed\u8a00\u6570\u7ec4\u521d\u59cb\u5316\u7684\u4e09\u79cd\u65b9\u6cd5"},"content":{"rendered":"

C\u8bed\u8a00\u4e2d\uff0c\u6570\u7ec4\u521d\u59cb\u5316\u7684\u65b9\u5f0f\u4e3b\u8981\u6709\u4e09\u79cd\uff1a<\/p>\n

1\u3001\u58f0\u660e\u65f6\uff0c\u4f7f\u7528 {0} \u521d\u59cb\u5316\uff1b<\/strong><\/p>\n

2\u3001\u4f7f\u7528memset\uff1b<\/strong><\/p>\n

3\u3001\u7528for\u5faa\u73af\u8d4b\u503c\u3002<\/strong><\/p>\n

\u90a3\u4e48\uff0c\u8fd9\u4e09\u79cd\u65b9\u6cd5\u7684\u539f\u7406\u4ee5\u53ca\u6548\u7387\u5982\u4f55\u5462\uff1f \u8bf7\u770b\u4e0b\u9762\u7684\u6d4b\u8bd5\u4ee3\u7801\uff1a<\/p>\n

#define ARRAY_SIZE_MAX  (1*1024*1024)\n \nvoid function1()\n{\n    char array[ARRAY_SIZE_MAX] = {0};  \/\/\u58f0\u660e\u65f6\u4f7f\u7528{0}\u521d\u59cb\u5316\u4e3a\u51680\n}\n \nvoid function2()\n{\n    char array[ARRAY_SIZE_MAX];\n    memset(array, 0, ARRAY_SIZE_MAX);  \/\/\u4f7f\u7528memset\u65b9\u6cd5\n}\n \nvoid function3()\n{\n    int i = 0;\n    char array[ARRAY_SIZE_MAX];\n    for (i = 0; i < ARRAY_SIZE_MAX; i++)  \/\/for\u5faa\u73af\u8d4b\u503c\n    {\n        array[i] = 0;\n    }\n}<\/code><\/pre>\n

\u6548\u7387\uff1a<\/strong><\/p>\n

\u5206\u522b\u6267\u884c\u4e0a\u9762\u4e09\u79cd\u65b9\u6cd5\uff0c\u7edf\u8ba1\u4e0b\u5e73\u5747\u65f6\u95f4\u53ef\u4ee5\u5f97\u51fa\uff1a  for\u5faa\u73af\u6d6a\u8d39\u7684\u65f6\u95f4\u6700\u591a\uff0c{0} \u4e0ememset \u8017\u65f6\u5dee\u4e0d\u591a\u3002<\/strong><\/p>\n

\u539f\u7406\uff1a<\/strong><\/p>\n

1\u3001for\u5faa\u73af\u8d4b\u503c\uff0c\u5c31\u662f\u5faa\u73af\u8d4b\u503c\uff0c\u4e0d\u89e3\u91ca\u4e86<\/p>\n

2\u3001memset\uff0c\u5f88\u5bb9\u6613\u627e\u5230memset\u5185\u90e8\u5b9e\u73b0\u4ee3\u7801\uff0c\u8fd9\u91cc\u4e5f\u4e0d\u89e3\u91ca\u4e86<\/p>\n

3\u3001{0} \u5185\u90e8\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u5462\uff1f<\/p>\n

\u5c06\u4e0a\u8ff0\u4ee3\u7801\u7f16\u8bd1\u6210\u6c47\u7f16\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n

function1\u5982\u4e0b\uff1a<\/p>\n

\tpushl\t%ebp\n\tmovl\t%esp, %ebp\n\tsubl\t$1048600, %esp\n\tleal\t-1048584(%ebp), %eax\n\tmovl\t$1048576, %edx\n\tmovl\t%edx, 8(%esp)\n\tmovl\t$0, 4(%esp)\n\tmovl\t%eax, (%esp)\n\tcall\tmemset\n\tleave\n\tret<\/code><\/pre>\n

function2\u5982\u4e0b\uff1a<\/p>\n

\tpushl\t%ebp\n\tmovl\t%esp, %ebp\n\tsubl\t$1048600, %esp\n\tmovl\t$1048576, 8(%esp)\n\tmovl\t$0, 4(%esp)\n\tleal\t-1048584(%ebp), %eax\n\tmovl\t%eax, (%esp)\n\tcall\tmemset\n\tleave\n\tret<\/code><\/pre>\n

\u901a\u8fc7\u6c47\u7f16\u4ee3\u7801\u53ef\u4ee5\u770b\u51fa\uff0c{0}\u521d\u59cb\u5316\u65b9\u5f0f\uff0c\u8c03\u7528\u4e86memset\u51fd\u6570\uff01
\u5bf9\u4e09\u79cd\u65b9\u6cd5\u7684\u9009\u53d6\uff1a<\/p>\n

1\u3001for \u6700\u6d6a\u8d39\u65f6\u95f4\uff0c\u4e0d\u5efa\u8bae\uff08\u5176\u5b9ememset\u5185\u90e8\u4e5f\u662f\u7528\u5faa\u73af\u5b9e\u73b0\u7684\uff0c\u53ea\u4e0d\u8fc7memset\u7ecf\u8fc7\u4e86\u4e25\u683c\u4f18\u5316\uff0c\u6240\u4ee5\u6027\u80fd\u66f4\u9ad8\uff09\uff1b<\/strong><\/p>\n

2\u3001{0} \u53ef\u80fd\u6709\u79fb\u690d\u6027\u95ee\u9898\uff0c\u867d\u7136\u7edd\u5927\u591a\u6570\u7f16\u8bd1\u5668\u770b\u5230{0} \u90fd\u662f\u5c06\u6570\u7ec4\u5168\u90e8\u521d\u59cb\u5316\u4e3a0\uff0c \u4f46\u662f\u4e0d\u4fdd\u8bc1\u6240\u6709\u7f16\u8bd1\u5668\u90fd\u662f\u8fd9\u6837\u5b9e\u73b0\u7684\uff1b<\/strong><\/p>\n

3\u3001\u7efc\u54081\u30012\uff0c \u63a8\u8350\u4f7f\u7528memset\u65b9\u6cd5\u3002<\/strong><\/p>\n

\u4e0a\u8ff0\u4ee3\u7801\uff0c\u7ed3\u679c\u4ee5\u53ca\u89c2\u70b9\u4ec5\u4ec5\u662f\u4e00\u5bb6\u4e4b\u8a00\uff0c\u5982\u679c\u6709\u95ee\u9898\uff0c\u591a\u8c22\u6307\u6b63\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"C\u8bed\u8a00\u6570\u7ec4\u521d\u59cb\u5316\u7684\u4e09\u79cd\u65b9\u6cd5C\u8bed\u8a00\u4e2d\uff0c\u6570\u7ec4\u521d\u59cb\u5316\u7684\u65b9\u5f0f\u4e3b\u8981\u6709\u4e09\u79cd\uff1a1\u3001\u58f0\u660e\u65f6\uff0c\u4f7f\u7528{0}\u521d\u59cb\u5316\uff1b2\u3001\u4f7f\u7528memset\uff1b3\u3001\u7528for\u5faa\u73af\u8d4b...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/320"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}