{"id":76701,"date":"2024-01-13T03:58:12","date_gmt":"2024-01-12T19:58:12","guid":{"rendered":"https:\/\/www.techphant.cn\/?p=76701"},"modified":"2024-01-13T03:58:12","modified_gmt":"2024-01-12T19:58:12","slug":"sdljmyghs","status":"publish","type":"post","link":"https:\/\/www.techphant.cn\/blog\/76701.html","title":{"rendered":"\u6df1\u5ea6\u4e86\u89e3malloc\u6709\u5173\u51fd\u6570"},"content":{"rendered":"
malloc\u6709\u5173\u51fd\u6570\u5728\u5185\u5b58\u7ba1\u7406\u4e2d\u626e\u6f14\u7740\u91cd\u8981\u89d2\u8272\u3002\u672c\u6587\u5c06\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\uff0c\u6df1\u5165\u63a2\u8ba8\u8fd9\u4e00\u4e3b\u9898\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u793a\u4f8b\u548c\u89e3\u91ca\uff0c\u5e2e\u52a9\u8bfb\u8005\u66f4\u52a0\u6df1\u5165\u4e86\u89e3malloc\u6709\u5173\u51fd\u6570\u3002\u5e0c\u671b\u672c\u6587\u80fd\u4e3a\u60a8\u5e26\u6765\u542f\u53d1\u548c\u77e5\u8bc6\u6536\u83b7\u3002<\/p>\n
malloc\u51fd\u6570\u662fC\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u5728\u5806\u4e0a\u5206\u914d\u4e00\u5757\u6307\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u5b83\u5e38\u5e38\u4e0efree\u51fd\u6570\u914d\u5408\u4f7f\u7528\uff0c\u7528\u4e8e\u52a8\u6001\u5206\u914d\u548c\u91ca\u653e\u5185\u5b58\u3002<\/p>\n
malloc\u7684\u539f\u7406\u662f\u5728\u5806\u4e0a\u5bfb\u627e\u4e00\u5757\u8db3\u591f\u5927\u7684\u7a7a\u95f2\u5185\u5b58\u533a\u57df\uff0c\u4ee5\u4fbf\u5b58\u50a8\u6307\u5b9a\u5927\u5c0f\u7684\u6570\u636e\u3002\u5982\u679c\u5806\u4e2d\u6ca1\u6709\u8db3\u591f\u7a7a\u95f4\uff0cmalloc\u5c06\u8fd4\u56deNULL\u6307\u9488\uff0c\u8868\u793a\u5206\u914d\u5931\u8d25\u3002<\/p>\n
\u4f7f\u7528malloc\u51fd\u6570\u5206\u914d\u5185\u5b58\u7684\u8bed\u6cd5\u4e3a\uff1avoid *malloc(size_t size);\u5176\u4e2dsize\u662f\u8981\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4\u7684\u5b57\u8282\u6570\uff0cmalloc\u51fd\u6570\u8fd4\u56de\u4e00\u4e2avoid\u7c7b\u578b\u7684\u6307\u9488\uff0c\u6307\u5411\u65b0\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4\u7684\u8d77\u59cb\u5730\u5740\u3002<\/p>\n
realloc\u51fd\u6570\u7528\u4e8e\u66f4\u6539\u4e4b\u524d\u5206\u914d\u7684\u5185\u5b58\u5757\u7684\u5927\u5c0f\u3002\u5b83\u53ef\u4ee5\u6269\u5927\u6216\u7f29\u5c0f\u5df2\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u5e76\u4fdd\u7559\u8be5\u5185\u5b58\u5757\u4e2d\u539f\u6709\u7684\u6570\u636e\u3002<\/p>\n
realloc\u51fd\u6570\u4e3b\u8981\u7528\u4e8e\u5728\u52a8\u6001\u5185\u5b58\u7ba1\u7406\u4e2d\uff0c\u5f53\u9700\u8981\u6539\u53d8\u5df2\u5206\u914d\u5185\u5b58\u7684\u5927\u5c0f\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528realloc\u6765\u5b9e\u73b0\u3002\u8fd9\u5728\u4e00\u4e9b\u52a8\u6001\u6570\u636e\u7ed3\u6784\u7684\u5b9e\u73b0\u4e2d\u7279\u522b\u6709\u7528\u3002<\/p>\n
\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8c03\u7528realloc\u51fd\u6570\u53ef\u80fd\u4f1a\u5c06\u5185\u5b58\u5757\u7684\u5730\u5740\u66f4\u6539\u4e3a\u65b0\u5730\u5740\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528realloc\u540e\uff0c\u4e4b\u524d\u6307\u5411\u8be5\u5185\u5b58\u5757\u7684\u5176\u4ed6\u6307\u9488\u90fd\u9700\u8981\u91cd\u65b0\u6307\u5b9a\u3002<\/p>\n
\u672c\u6587\u4ecb\u7ecd\u4e86malloc\u6709\u5173\u51fd\u6570\uff0c\u5305\u62ecmalloc\u51fd\u6570\u7684\u539f\u7406\u548c\u4f7f\u7528\u65b9\u6cd5\uff0c\u4ee5\u53carealloc\u51fd\u6570\u7684\u4f7f\u7528\u573a\u666f\u548c\u6ce8\u610f\u4e8b\u9879\u3002<\/strong>\u6df1\u5165\u4e86\u89e3malloc\u6709\u5173\u51fd\u6570\u6709\u52a9\u4e8e\u66f4\u597d\u5730\u7406\u89e3\u5185\u5b58\u7ba1\u7406\uff0c\u63d0\u5347\u4ee3\u7801\u7684\u5065\u58ee\u6027\u548c\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" malloc\u6709\u5173\u51fd\u6570\u5728\u5185\u5b58\u7ba1\u7406\u4e2d\u626e\u6f14\u7740\u91cd\u8981\u89d2\u8272\u3002\u672c\u6587\u5c06\u5206\u4e3a\u4e09\u4e2a\u90e8\u5206\uff0c\u6df1\u5165\u63a2\u8ba8\u8fd9\u4e00\u4e3b\u9898\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u793a\u4f8b\u548c\u89e3\u91ca\uff0c\u5e2e\u52a9\u8bfb\u8005\u66f4\u52a0\u6df1\u5165\u4e86\u89e3malloc\u6709\u5173\u51fd\u6570\u3002\u5e0c\u671b\u672c\u6587\u80fd\u4e3a\u60a8\u5e26\u6765\u542f<\/p>\n","protected":false},"author":1,"featured_media":64183,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[36],"tags":[305],"class_list":["post-76701","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-dzjs"],"_links":{"self":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/76701","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/comments?post=76701"}],"version-history":[{"count":0,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/76701\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media\/64183"}],"wp:attachment":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media?parent=76701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/categories?post=76701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/tags?post=76701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}