{"id":62385,"date":"2026-01-19T23:06:02","date_gmt":"2026-01-19T15:06:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/62385.html"},"modified":"2026-01-19T23:06:02","modified_gmt":"2026-01-19T15:06:02","slug":"c%e8%af%ad%e8%a8%80%e9%9d%a2%e8%af%95%e7%af%87%ef%bc%9ac-c%e4%b8%ad%e7%9a%84malloc-free%e5%92%8cnew-delete","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/62385.html","title":{"rendered":"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete"},"content":{"rendered":"<h2>\u6838\u5fc3\u533a\u522b&#xff08;\u56db\u4e2a\u70b9&#xff09; \u65e0\u8111\u8bb0\u4f4f&#xff01;&#xff01;&#xff01;<\/h2>\n<h3>\u4e00&#xff1a;\u8bed\u8a00\u5f52\u5c5e\u4e0e\u7c7b\u578b\u652f\u6301<\/h3>\n<p><span style=\"color:#fe2c24\">malloc\/free\u662f C \u8bed\u8a00&lt;stdlib.h&gt;\u5e93\u63d0\u4f9b\u7684\u57fa\u7840\u51fd\u6570<\/span>&#xff0c;\u5b8c\u5168\u670d\u52a1\u4e8e C \u8bed\u8a00 \u201c\u9762\u5411\u8fc7\u7a0b\u3001\u8f7b\u91cf\u9ad8\u6548\u201d \u7684\u8bbe\u8ba1\u7406\u5ff5\u3002<\/p>\n<p>\u5176\u6838\u5fc3\u7279\u5f81\u662f\u65e0\u7c7b\u578b\u611f\u77e5&#xff1a;malloc\u4ec5\u6839\u636e\u4f20\u5165\u7684\u5b57\u8282\u6570\u5206\u914d\u5185\u5b58\u5757&#xff0c;\u8fd4\u56de\u503c\u4e3avoid*&#xff08;\u65e0\u7c7b\u578b\u6307\u9488&#xff09;&#xff0c;\u8fd9\u610f\u5473\u7740\u5b83\u65e0\u6cd5\u8bc6\u522b\u5185\u5b58\u7684\u5b9e\u9645\u7528\u9014&#xff0c;\u4f7f\u7528\u65f6\u5fc5\u987b\u901a\u8fc7\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362&#xff08;\u5982(int*)malloc(10 * sizeof(int))&#xff09;\u5c06void*\u8f6c\u4e3a\u76ee\u6807\u7c7b\u578b\u6307\u9488\u3002<\/p>\n<p>\u8fd9\u79cd\u624b\u52a8\u8f6c\u6362\u4e0d\u4ec5\u589e\u52a0\u4ee3\u7801\u5197\u4f59&#xff0c;\u8fd8\u5b58\u5728\u7c7b\u578b\u4e0d\u5339\u914d\u7684\u98ce\u9669&#xff1a;<\/p>\n<p>#include &lt;stdlib.h&gt;<br \/>\nint main() {<br \/>\n    \/\/ \u6b63\u786e\u7528\u6cd5&#xff1a;\u5206\u914d10\u4e2aint\u7a7a\u95f4\u5e76\u5f3a\u5236\u8f6c\u6362<br \/>\n    int* int_arr &#061; (int*)malloc(10 * sizeof(int));<\/p>\n<p>    \/\/ \u5371\u9669\u64cd\u4f5c&#xff1a;\u9519\u8bef\u8f6c\u6362\u4e3adouble\u6307\u9488<br \/>\n    double* wrong_ptr &#061; (double*)malloc(10 * sizeof(int));<br \/>\n    wrong_ptr[0] &#061; 3.14; \/\/ \u53ef\u80fd\u7834\u574f\u5185\u5b58\u5e03\u5c40<br \/>\n    free(int_arr);<br \/>\n    free(wrong_ptr);<br \/>\n}<\/p>\n<p><span style=\"color:#fe2c24\">new\/delete\u662f C&#043;&#043; \u8bed\u8a00\u539f\u751f\u8fd0\u7b97\u7b26&#xff0c;\u4e3a\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u91cf\u8eab\u8bbe\u8ba1&#xff0c;\u5929\u7136\u5177\u5907\u7c7b\u578b\u5b89\u5168\u6027<\/span>\u3002new\u4f1a\u6839\u636e\u540e\u7eed\u6307\u5b9a\u7684\u7c7b\u578b&#xff08;\u5982new int\u3001new MyClass&#xff09;\u81ea\u52a8\u63a8\u5bfc\u5185\u5b58\u5757\u7684\u7c7b\u578b&#xff0c;\u76f4\u63a5\u8fd4\u56de\u5bf9\u5e94\u7c7b\u578b\u7684\u6307\u9488&#xff0c;\u65e0\u9700\u624b\u52a8\u5f3a\u5236\u8f6c\u6362\u3002\u4f8b\u5982int* arr &#061; new int[10]&#xff0c;new\u76f4\u63a5\u8fd4\u56deint*\u7c7b\u578b&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u4e25\u683c\u6821\u9a8c\u6307\u9488\u7c7b\u578b\u4e0e\u63a5\u6536\u53d8\u91cf\u7684\u5339\u914d\u6027&#xff0c;\u4ece\u8bed\u6cd5\u5c42\u9762\u675c\u7edd\u7c7b\u578b\u8f6c\u6362\u9519\u8bef&#xff0c;\u5927\u5e45\u63d0\u5347\u4ee3\u7801\u53ef\u9760\u6027\u3002<\/p>\n<p>new\/delete\u662fC&#043;&#043;\u8fd0\u7b97\u7b26&#xff0c;\u81ea\u52a8\u8fd4\u56de\u8be5\u7c7b\u578b\u7684\u6307\u9488\u3002<\/p>\n<p>class MyClass { int data; };<br \/>\nint main() {<br \/>\n    \/\/ \u81ea\u52a8\u7c7b\u578b\u63a8\u5bfc&#xff1a;\u65e0\u9700\u8f6c\u6362<br \/>\n    int* arr &#061; new int[10];<br \/>\n    MyClass* obj &#061; new MyClass();<\/p>\n<p>    \/\/ \u7c7b\u578b\u68c0\u67e5&#xff1a;\u4ee5\u4e0b\u4ee3\u7801\u4f1a\u76f4\u63a5\u7f16\u8bd1\u5931\u8d25<br \/>\n    \/\/ double* err &#061; new int[10]; <\/p>\n<p>    delete[] arr;<br \/>\n    delete obj;<br \/>\n}<\/p>\n<h3>\u4e8c&#xff1a;\u521d\u59cb\u5316\u4e0e\u5bf9\u8c61\u7ba1\u7406<\/h3>\n<p>\n<span style=\"color:#fe2c24\">malloc\u4ec5\u5206\u914d\u5185\u5b58&#xff0c;\u4e0d\u521d\u59cb\u5316&#xff1b;free\u4e0d\u8c03\u7528\u6790\u6784\u51fd\u6570\u3002<\/span><\/p>\n<p><span style=\"color:#fe2c24\">new\u4f1a\u8c03\u7528\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316&#xff0c;delete\u5148\u8c03\u7528\u6790\u6784\u51fd\u6570\u518d\u91ca\u653e\u5185\u5b58\u3002<\/span><\/p>\n<p><span style=\"color:null\">&#8212;&#8212;&#8212;&#8212;-\u8fd9\u662f\u4e8c\u8005\u6700\u6838\u5fc3\u7684\u5dee\u5f02&#xff0c;\u76f4\u63a5\u51b3\u5b9a\u4e86\u5bf9 \u201c\u5bf9\u8c61\u201d \u7684\u7ba1\u7406\u80fd\u529b\u3002<\/span><\/p>\n<p>malloc\u7684\u529f\u80fd\u4ec5\u5c40\u9650\u4e8e \u201c\u5206\u914d\u6307\u5b9a\u5b57\u8282\u6570\u7684\u539f\u59cb\u5185\u5b58\u201d&#xff0c;\u4e0d\u4f1a\u5bf9\u5185\u5b58\u5185\u5bb9\u505a\u4efb\u4f55\u521d\u59cb\u5316&#xff0c;\u5206\u914d\u540e\u7684\u5185\u5b58\u4e2d\u662f\u968f\u673a\u7684\u5783\u573e\u503c&#xff0c;\u9700\u5f00\u53d1\u8005\u624b\u52a8\u8d4b\u503c&#xff0c;free\u540c\u6837\u5982\u6b64;<\/p>\n<p>new\/delete\u5219\u6df1\u5ea6\u7ed1\u5b9a\u5bf9\u8c61\u7684\u751f\u547d\u5468\u671f&#xff1a;new\u5728\u5206\u914d\u5185\u5b58\u540e&#xff0c;\u4f1a\u81ea\u52a8\u8c03\u7528\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570&#xff08;\u9ed8\u8ba4\u6784\u9020\u3001\u6709\u53c2\u6784\u9020\u5747\u53ef&#xff09;&#xff0c;\u5b8c\u6210\u6210\u5458\u53d8\u91cf\u521d\u59cb\u5316\u3001\u52a8\u6001\u8d44\u6e90\u7533\u8bf7\u7b49\u6838\u5fc3\u64cd\u4f5c<\/p>\n<h3>\u4e09&#xff1a;\u5185\u5b58\u5927\u5c0f\u8ba1\u7b97<\/h3>\n<p>\n<span style=\"color:#fe2c24\">malloc\u9700\u624b\u52a8\u8ba1\u7b97\u5b57\u8282\u6570&#xff08;\u5982malloc(10*sizeof(int))&#xff09;&#xff1b;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">new\u81ea\u52a8\u63a8\u5bfc\u5927\u5c0f&#xff08;\u5982new int[10]&#xff09;\u3002<\/span><\/p>\n<\/p>\n<h3>\u56db&#xff1a;\u5f02\u5e38\u5904\u7406<\/h3>\n<p>\n<span style=\"color:#fe2c24\">malloc\u5931\u8d25\u8fd4\u56deNULL&#xff1b;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">new\u5931\u8d25\u629b\u51fastd::bad_alloc\u5f02\u5e38\u3002<\/span><\/p>\n<p>\u4ee3\u7801\u9644\u4e0a&#xff1a;<\/p>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;cstdlib&gt;<br \/>\n#include &lt;exception&gt;<br \/>\nusing namespace std;<\/p>\n<p>class Test {<br \/>\npublic:<br \/>\n    Test() { cout &lt;&lt; &#034;\u6784\u9020\u51fd\u6570\u521d\u59cb\u5316&#034; &lt;&lt; endl; }<br \/>\n    ~Test() { cout &lt;&lt; &#034;\u6790\u6784\u51fd\u6570\u6e05\u7406\u8d44\u6e90&#034; &lt;&lt; endl; }<br \/>\n};<\/p>\n<p>int main() {<br \/>\n    \/\/ C\u65b9\u5f0f&#xff1a;\u624b\u52a8\u8f6c\u6362&#043;\u68c0\u67e5NULL<br \/>\n    int* c_p &#061; (int*)malloc(sizeof(int));<br \/>\n    if (c_p) *c_p &#061; 10;<\/p>\n<p>    \/\/ C&#043;&#043;\u65b9\u5f0f&#xff1a;\u81ea\u52a8\u7c7b\u578b&#043;\u5f02\u5e38\u5904\u7406<br \/>\n    try {<br \/>\n        Test* t &#061; new Test(); \/\/ \u81ea\u52a8\u8c03\u7528\u6784\u9020\u51fd\u6570<br \/>\n        int* cpp_p &#061; new int(20); \/\/ \u81ea\u52a8\u63a8\u5bfc\u5927\u5c0f&#043;\u521d\u59cb\u5316<br \/>\n        delete t; \/\/ \u5148\u6790\u6784\u518d\u91ca\u653e<br \/>\n        delete cpp_p;<br \/>\n    } catch (const bad_alloc&amp; e) {<br \/>\n        cout &lt;&lt; &#034;\u5185\u5b58\u5206\u914d\u5931\u8d25&#xff1a;&#034; &lt;&lt; e.what() &lt;&lt; endl;<br \/>\n    }<br \/>\n    free(c_p);<br \/>\n    return 0;<br \/>\n}<\/p>\n<h3>\u5173\u952e\u5dee\u5f02\u603b\u7ed3&#xff1a;<\/h3>\n<p>malloc\/free\u662f C \u8bed\u8a00\u7684 \u201c\u57fa\u7840\u5185\u5b58\u5de5\u5177\u201d&#xff0c;\u4ec5\u5173\u6ce8\u5185\u5b58\u5757\u7684\u5206\u914d\u4e0e\u91ca\u653e&#xff0c;\u9002\u914d\u7b80\u5355\u573a\u666f\u548c\u8de8\u8bed\u8a00\u4ea4\u4e92&#xff0c;\u4f46\u9700\u624b\u52a8\u5904\u7406\u7c7b\u578b\u3001\u521d\u59cb\u5316\u3001\u9519\u8bef\u68c0\u67e5\u7b49\u95ee\u9898&#xff1b;new\/delete\u662f C&#043;&#043; \u7684 \u201c\u667a\u80fd\u5bf9\u8c61\u7ba1\u5bb6\u201d&#xff0c;\u6574\u5408\u4e86\u5185\u5b58\u7ba1\u7406\u4e0e\u5bf9\u8c61\u751f\u547d\u5468\u671f\u7ba1\u7406&#xff0c;\u5177\u5907\u7c7b\u578b\u5b89\u5168\u3001\u81ea\u52a8\u5316\u3001\u5f02\u5e38\u53cb\u597d\u7b49\u4f18\u52bf&#xff0c;\u662f C&#043;&#043; \u9879\u76ee\u7ba1\u7406\u52a8\u6001\u5bf9\u8c61\u7684\u9996\u9009\u3002\u5b9e\u9645\u5f00\u53d1\u4e2d\u9700\u6839\u636e\u8bed\u8a00\u73af\u5883\u9009\u578b&#xff0c;\u907f\u514d\u6df7\u7528\u4e8c\u8005\u5bfc\u81f4\u5185\u5b58\u9519\u8bef\u3002<\/p>\n<table>\n<tr>\u7ef4\u5ea6malloc\/freenew\/delete<\/tr>\n<tbody>\n<tr>\n<td>\u7c7b\u578b\u5b89\u5168<\/td>\n<td>\u9700\u624b\u52a8\u7c7b\u578b\u8f6c\u6362<\/td>\n<td>\u81ea\u52a8\u7c7b\u578b\u63a8\u5bfc<\/td>\n<\/tr>\n<tr>\n<td>\u5bf9\u8c61\u751f\u547d\u5468\u671f<\/td>\n<td>\u4e0d\u7ba1\u7406\u6784\u9020\/\u6790\u6784<\/td>\n<td>\u81ea\u52a8\u8c03\u7528\u6784\u9020\/\u6790\u6784<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u5b58\u8ba1\u7b97<\/td>\n<td>\u624b\u52a8\u8ba1\u7b97\u5b57\u8282\u6570<\/td>\n<td>\u7f16\u8bd1\u5668\u81ea\u52a8\u8ba1\u7b97<\/td>\n<\/tr>\n<tr>\n<td>\u9519\u8bef\u5904\u7406<\/td>\n<td>\u8fd4\u56deNULL\u9700\u663e\u5f0f\u68c0\u67e5<\/td>\n<td>\u629b\u51fa\u5f02\u5e38<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u6838\u5fc3\u533a\u522b&#xff08;\u56db\u4e2a\u70b9&#xff09; \u65e0\u8111\u8bb0\u4f4f&#xff01;&#xff01;&#xff01;\u4e00&#xff1a;\u8bed\u8a00\u5f52\u5c5e\u4e0e\u7c7b\u578b\u652f\u6301malloc\/free\u662f C \u8bed\u8a00\u5e93\u63d0\u4f9b\u7684\u57fa\u7840\u51fd\u6570&#xff0c;\u5b8c\u5168\u670d\u52a1\u4e8e C \u8bed\u8a00 \u201c\u9762\u5411\u8fc7\u7a0b\u3001\u8f7b\u91cf\u9ad8\u6548\u201d \u7684\u8bbe\u8ba1\u7406\u5ff5\u3002\u5176\u6838\u5fc3\u7279\u5f81\u662f\u65e0\u7c7b\u578b\u611f\u77e5&#xff1a;malloc\u4ec5\u6839\u636e\u4f20\u5165\u7684\u5b57\u8282\u6570\u5206\u914d\u5185\u5b58\u5757&#xff0c;\u8fd4\u56de\u503c\u4e3avoid*&#xff08;\u65e0\u7c7b\u578b\u6307\u9488&#xff09;&#xff0c;\u8fd9\u610f\u5473\u7740\u5b83\u65e0\u6cd5\u8bc6\u522b\u5185\u5b58\u7684\u5b9e<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,174,190,925,176],"topic":[],"class_list":{"0":"post-62385","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-c","9":"tag-190","10":"tag-925","11":"tag-176"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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.wsisp.com\/helps\/62385.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6838\u5fc3\u533a\u522b&#xff08;\u56db\u4e2a\u70b9&#xff09; \u65e0\u8111\u8bb0\u4f4f&#xff01;&#xff01;&#xff01;\u4e00&#xff1a;\u8bed\u8a00\u5f52\u5c5e\u4e0e\u7c7b\u578b\u652f\u6301malloc\/free\u662f C \u8bed\u8a00\u5e93\u63d0\u4f9b\u7684\u57fa\u7840\u51fd\u6570&#xff0c;\u5b8c\u5168\u670d\u52a1\u4e8e C \u8bed\u8a00 \u201c\u9762\u5411\u8fc7\u7a0b\u3001\u8f7b\u91cf\u9ad8\u6548\u201d \u7684\u8bbe\u8ba1\u7406\u5ff5\u3002\u5176\u6838\u5fc3\u7279\u5f81\u662f\u65e0\u7c7b\u578b\u611f\u77e5&#xff1a;malloc\u4ec5\u6839\u636e\u4f20\u5165\u7684\u5b57\u8282\u6570\u5206\u914d\u5185\u5b58\u5757&#xff0c;\u8fd4\u56de\u503c\u4e3avoid*&#xff08;\u65e0\u7c7b\u578b\u6307\u9488&#xff09;&#xff0c;\u8fd9\u610f\u5473\u7740\u5b83\u65e0\u6cd5\u8bc6\u522b\u5185\u5b58\u7684\u5b9e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/62385.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-19T15:06:02+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62385.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/62385.html\",\"name\":\"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-19T15:06:02+00:00\",\"dateModified\":\"2026-01-19T15:06:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/62385.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/62385.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62385.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/62385.html","og_locale":"zh_CN","og_type":"article","og_title":"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6838\u5fc3\u533a\u522b&#xff08;\u56db\u4e2a\u70b9&#xff09; \u65e0\u8111\u8bb0\u4f4f&#xff01;&#xff01;&#xff01;\u4e00&#xff1a;\u8bed\u8a00\u5f52\u5c5e\u4e0e\u7c7b\u578b\u652f\u6301malloc\/free\u662f C \u8bed\u8a00\u5e93\u63d0\u4f9b\u7684\u57fa\u7840\u51fd\u6570&#xff0c;\u5b8c\u5168\u670d\u52a1\u4e8e C \u8bed\u8a00 \u201c\u9762\u5411\u8fc7\u7a0b\u3001\u8f7b\u91cf\u9ad8\u6548\u201d \u7684\u8bbe\u8ba1\u7406\u5ff5\u3002\u5176\u6838\u5fc3\u7279\u5f81\u662f\u65e0\u7c7b\u578b\u611f\u77e5&#xff1a;malloc\u4ec5\u6839\u636e\u4f20\u5165\u7684\u5b57\u8282\u6570\u5206\u914d\u5185\u5b58\u5757&#xff0c;\u8fd4\u56de\u503c\u4e3avoid*&#xff08;\u65e0\u7c7b\u578b\u6307\u9488&#xff09;&#xff0c;\u8fd9\u610f\u5473\u7740\u5b83\u65e0\u6cd5\u8bc6\u522b\u5185\u5b58\u7684\u5b9e","og_url":"https:\/\/www.wsisp.com\/helps\/62385.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-19T15:06:02+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/62385.html","url":"https:\/\/www.wsisp.com\/helps\/62385.html","name":"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-19T15:06:02+00:00","dateModified":"2026-01-19T15:06:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/62385.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/62385.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/62385.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"C\u8bed\u8a00\u9762\u8bd5\u7bc7\uff1aC\/C++\u4e2d\u7684malloc\/free\u548cnew\/delete"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=62385"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62385\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=62385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=62385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=62385"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=62385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}