{"id":221386,"date":"2020-11-29T19:13:14","date_gmt":"2020-11-29T11:13:14","guid":{"rendered":"http:\/\/4563.org\/?p=221386"},"modified":"2020-11-29T19:13:14","modified_gmt":"2020-11-29T11:13:14","slug":"python-%e8%b0%83%e7%94%a8-c-%e6%8f%92%e4%bb%b6%e5%90%8e%ef%bc%8c%e9%9c%80%e8%a6%81%e6%89%8b%e5%8a%a8%e9%87%8a%e6%94%be%e5%86%85%e5%ad%98%e5%90%97%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=221386","title":{"rendered":"Python \u8c03\u7528 C \u63d2\u4ef6\u540e\uff0c\u9700\u8981\u624b\u52a8\u91ca\u653e\u5185\u5b58\u5417\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u8c03\u7528 C \u63d2\u4ef6\u540e\uff0c\u9700\u8981\u624b\u52a8\u91ca\u653e\u5185\u5b58\u5417\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u5982\u9898\uff0c\u6700\u8fd1\u5728\u7528 cython \u505a\u5c40\u90e8\u52a0\u901f\uff0c\u5df2\u7ecf\u53d1\u4e86\u51e0\u4e2a\u5e16\u5b50\u4e86\u3002\u76ee\u524d\u9879\u76ee\u8fdb\u5c55\u987a\u5229\uff0c\u8bd5\u505a\u578b\u4ee3\u7801\u91cf\u6bd4 py \u5927\u4e09\u500d\u5de6\u53f3\uff0c\u8fd0\u884c\u901f\u5ea6\u5feb 200 \u500d\uff0c\u5df2\u7ecf\u5f88\u6ee1\u610f\u4e86\u3002<\/p>\n<p>\u8003\u8651\u5230\u4e00\u4e2a\u90e8\u7f72\u7684\u95ee\u9898\u662f\uff0c\u6211\u4e0d\u592a\u6e05\u695a py \u548c so \u4ea4\u4e92\u7684\u539f\u7406\uff0c\u5982\u679c\u8c03\u7528 so \u51fd\u6570\uff0cso \u5f00\u8f9f\u7684\u5185\u5b58\u7a7a\u95f4\u8fd8\u53d7\u5230 py \u89e3\u91ca\u5668\u63a7\u5236\u5417\uff1f\u5f53\u5b8c\u6210\u8c03\u7528\uff0c\u8fd4\u56de\u7ed3\u679c\u65f6\uff0c\u5b83\u662f\u5426\u4f1a\u50cf\u4e00\u4e2a py \u51fd\u6570\u4e00\u6837\u56de\u6536\u6574\u4e2a\u547d\u540d\u7a7a\u95f4\u5185\u7684\u5185\u5b58\uff1f(\u6240\u4ee5\u6211\u4e0d\u9700\u8981\u624b\u52a8\u56de\u6536\u5bb9\u5668\u7684\u5185\u5b58)<\/p>\n<p>\u8fd8\u662f\u8bf4\u6211\u5fc5\u987b\u56de\u6536\u6211\u521b\u5efa\u7684\u6bcf\u4e2a\u5bb9\u5668\u7684\u5185\u5b58\uff0c\u4e0d\u56de\u6536\u5c31\u4f1a\u5f15\u53d1\u6cc4\u9732\uff1f      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4466923\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : cz5424 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9700\u8981\u56de\u6536                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466924\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u4e0d\u719f\u6089 cython\uff0c\u4ee5\u4e0b\u8bf4\u6cd5\u662f\u57fa\u4e8e ctypes \u8c03\u7528\u5916\u90e8\u5e93\u3002<\/p>\n<p>&gt; so \u5f00\u8f9f\u7684\u5185\u5b58\u7a7a\u95f4\u8fd8\u53d7\u5230 py \u89e3\u91ca\u5668\u63a7\u5236\u5417<br \/>\u5916\u90e8\u5e93\u5206\u914d\u7684\u6570\u636e\uff0c\u4e00\u822c\u662f\u8981\u8c03\u7528\u5916\u90e8\u5e93\u5bf9\u5e94\u7684\u91ca\u653e\u51fd\u6570\u6765\u91ca\u653e\u7684\uff0c\u4e0d\u53d7 Python \u89e3\u6790\u5668\u63a7\u5236\u3002\u4e25\u683c\u6765\u8bf4 Python \u89e3\u6790\u5668\u90fd\u4e0d\u5173\u5fc3\u8fd9\u6570\u636e\u662f\u4ec0\u4e48\u3002<\/p>\n<p>&gt; \u6240\u4ee5\u6211\u4e0d\u9700\u8981\u624b\u52a8\u56de\u6536\u5bb9\u5668\u7684\u5185\u5b58<br \/>\u662f\u8981\u7684\uff0c\u9664\u975e\u4f60\u7528 Python \u7c7b\u5305\u88c5\u4e00\u4e0b\uff0c\u7136\u540e\u5728\u6790\u6784\u51fd\u6570\u4e2d\u91ca\u653e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466925\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fasionchan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5982\u679c\u4f60\u5728 c \u4e2d\u7533\u8bf7\u5185\u5b58(malloc)\uff0c\u90a3\u4e48\u9700\u8981\u81ea\u5df1\u505a\u597d\u5185\u5b58\u7ba1\u7406\uff0c\u8be5\u91ca\u653e\u65f6\u5c31\u8981\u91ca\u653e(free)\uff0c\u4e0d\u7136\u5c31\u662f\u5185\u5b58\u6cc4\u9732\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5728 c \u4e2d\u521b\u5efa Python \u5bf9\u8c61\uff0c\u9700\u8981\u901a\u8fc7 Py_INCREF\/Py_DECREF \u8fd9\u4e24\u4e2a\u5b8f\u7ef4\u62a4\u597d\u5f15\u7528\u8ba1\u6570\uff0cPython \u865a\u62df\u673a\u4f1a\u6839\u636e\u5f15\u7528\u8ba1\u6570\u51b3\u5b9a\u4ec0\u4e48\u65f6\u5019\u91ca\u653e\u5185\u5b58\u3002<\/p>\n<p>\u90a3\u4e48\u4ec0\u4e48\u65f6\u5019\u9700\u8981\u8c03\u6574\u5f15\u7528\u8ba1\u6570\u5462\uff1f\u5178\u578b\u7684\u573a\u666f\u5305\u62ec\uff1a\u5bf9\u8c61\u88ab\u6dfb\u52a0\u5230\u5bb9\u5668\u4e2d\uff0c\u6216\u8005\u5bf9\u8c61\u4f5c\u4e3a\u51fd\u6570\u7ed3\u679c\u8fd4\u56de\u65f6\u7b49\u7b49\u3002<br \/>\u5982\u679c\u5f15\u7528\u8ba1\u6570\u7ef4\u62a4\u4e0d\u5f53\uff0c\u8f7b\u5219\u5185\u5b58\u6cc4\u9732(\u8be5\u51cf\u6ca1\u51cf)\uff0c\u91cd\u5219\u5185\u5b58\u975e\u6cd5\u8bbf\u95ee(\u8be5\u52a0\u6ca1\u52a0)\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466926\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ysc3839 <br \/>@fasionchan <br \/>\u611f\u8c22\u56de\u590d\uff0c\u6211\u662f\u8c03\u7528\u7684 C++stl \u7684\u6570\u636e\u7ed3\u6784\uff0c\u7528\u6765\u5bf9\u63a5 python \u7684\u5217\u8868\uff0c\u4e0d\u662f\u7528 malloc \u7684\u5f62\u5f0f\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u8981\u5982\u4f55\u6e05\u7406\u5185\u5b58\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466927\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fasionchan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black \u4e00\u6837\u7684\u3002\u5982\u679c\u4f60\u901a\u8fc7 new \u521b\u5efa\u4e86 c++\u5bf9\u8c61\uff0c\u5bf9\u8c61\u4e0d\u7528\u540e\u8981\u901a\u8fc7 delete \u8fdb\u884c\u91ca\u653e\u3002\u5982\u679c\u901a\u8fc7\u7c7b\u4f3c\u667a\u80fd\u6307\u9488\u7684\u4e1c\u897f\u6765\u7ba1\u7406\uff0c\u5219\u9075\u5b88\u667a\u80fd\u6307\u9488\u7684\u7ea6\u5b9a\u5373\u53ef\uff0c\u4e0d\u7528\u663e\u5f0f\u91ca\u653e\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466928\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : evilcoming <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u822c\u63d2\u4ef6\u90fd\u4f1a\u8d1f\u8d23\u56de\u6536\u5185\u5b58\uff0c\u5982\u679c\u63d2\u4ef6\u6ca1\u6709\u56de\u6536\uff0c\u4f60\u8981\u5728\u63d2\u4ef6\u6e90\u7801\u4e2d\u7528 c \u56de\u6536\uff0c\u800c\u4e0d\u662f\u7528 python \u56de\u6536\u5185\u5b58                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466929\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : black11black <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @fasionchan \u6211\u505a\u7684\u4e3b\u8981\u64cd\u4f5c\u662f\u521b\u5efa\u5411\u91cf\uff0cmap \u4e4b\u7c7b\u7684\uff0c\u7136\u540e\u5411\u91cc\u9762 push_back \u6570\u636e\u3002\u8fd9\u79cd\u662f\u5426\u662f\u7c7b\u4f3c\u667a\u80fd\u6307\u9488\u7684\u60c5\u51b5\uff1f\u6211\u7684\u5408\u7406\u5904\u7406\u65b9\u5f0f\u662f\u5426\u662f\u5728\u4f7f\u7528\u5b8c\u6bd5\u8fc7\u540e\u4f7f\u7528 vector.clear() \uff0c\u7136\u540e\u60f3\u529e\u6cd5 delete \u8fd9\u4e2a vector\uff0c\u5c31\u53ef\u4ee5\u786e\u4fdd\u4e0d\u6cc4\u9732\uff1f<\/p>\n<p>\u53e6\u5916\u6211\u5411 vector \u91cc\u52a0\u5165\u7684\u4e0d\u662f\u7c7b\u4f3c double \u8fd9\u79cd\u539f\u751f\u6570\u636e\u7ed3\u6784\uff0c\u800c\u662f struct\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u662f\u5426\u662f\u6bcf\u4e00\u4e2a\u9879\u76ee\u90fd\u8981\u9010\u4e2a\u5220\u9664\uff0c\u800c clear()\u4e0d\u80fd\u7edf\u4e00\u91ca\u653e\uff1f<\/p>\n<p>\u8c22\u8c22                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466930\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fasionchan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @black11black \u7b2c\u4e00\u4e2a\u95ee\u9898\uff1a\u4f60\u5e94\u8be5\u4e0d\u662f\u7528\u667a\u80fd\u6307\u9488\uff0c\u5904\u7406\u65b9\u5f0f\u662f\u5bf9\u7684\u3002delete vector \u5176\u5b9e\u5c31\u4f1a\u6267\u884c clear\uff0c\u6240\u4ee5 clear \u4e0d\u662f\u5fc5\u987b\u7684\u3002<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u95ee\u9898\uff0c\u8c03\u7528 clear \u4f1a\u5bf9\u6bcf\u4e2a\u5143\u7d20\u8c03\u7528\u6790\u6784\u51fd\u6570\uff0c\u6790\u6784\u51fd\u6570\u51fd\u6570\u4e00\u822c\u5c31\u662f\u7528\u6765\u91ca\u653e\u8d44\u6e90\u7684\uff0c\u56e0\u6b64\u65e0\u9700\u9010\u4e2a\u5220\u9664\u3002\u5982\u679c\u4f60\u7684 struct \u5f15\u7528\u4e86\u5176\u4ed6\u5185\u5b58\u8d44\u6e90\uff0c\u4f8b\u5982 new \u4e86\u4ec0\u4e48\u5176\u4ed6\u5bf9\u8c61\uff0c\u5219\u9700\u8981\u5728\u6790\u6784\u51fd\u6570\u4e2d\u5c06\u5b83 delete \u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4466931\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sujin190 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9996\u5148 cython \u662f\u4e2a\u8f6c\u8bd1\u5668\u4e0d\u662f\u7f16\u8bd1\u5668\uff0c\u66f4\u4e0d\u662f\u865a\u62df\u673a\u8fd0\u884c\u65f6\uff0c\u6240\u4ee5 python \u8fd8\u662f python\uff0cc++\u8fd8\u662f c++\uff0c\u8be5\u548b\u6ef4\u8fd8\u548b\u6ef4\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u8c03\u7528 C \u63d2\u4ef6\u540e\uff0c\u9700&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/221386"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=221386"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/221386\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=221386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=221386"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=221386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}