{"id":567,"date":"2016-11-08T17:35:53","date_gmt":"2016-11-08T09:35:53","guid":{"rendered":"https:\/\/carlos.aboutmy.info\/blog\/?p=567"},"modified":"2016-11-08T17:35:53","modified_gmt":"2016-11-08T09:35:53","slug":"c-string-stack-overflow","status":"publish","type":"post","link":"https:\/\/carlos.aboutmy.info\/blog\/?p=567","title":{"rendered":"C++ string stack overflow"},"content":{"rendered":"<p>\u6536\u5230\u4e00\u500b Win32 C++ program\uff0c\u767c\u89ba input \u5927 file \u6642\uff0c\u57f7\u884c\u9014\u4e2d\u6703\u639b\u6389\u3002\u67e5\u770b source code \u5f8c\u4f30\u8a08\u597d\u5927\u6a5f\u6703\u662f\u56e0\u70ba stack overflow\u3002<\/p>\n<p>\u6539\u5de6\u5e7e\u53e5\uff0c\u628a wstring \u6539\u505a wchar_t \u53ca\u6539\u57cb\u76f8\u95dc\u7684 functions \u4fbf\u89e3\u6c7a\u4e86 stack overflow \u554f\u984c\u3002\u539f\u56e0\u662f\u300c\u65b0\u300dC++ STL \u662f\u6703\u628a\u77ed string \u653e stack\uff0c\u9577 string \u624d\u653e heap\uff0c\u5481\u505a\u662f\u70ba\u5de6 performance \u8003\u91cf\uff0c\u8981\u77e5\u9053 stack \u5feb\u904e heap \u597d\u591a\u3002\u4f46\u8d85\u5927\u91cf\u77ed string \u5c31\u6703\u505a\u6210 stack overflow\u3002\u7d50\u679c\u4fee\u6539\u5f8c\uff0c\u4fbf\u80fd\u6b63\u5e38\u904b\u884c\u3002<\/p>\n<p>\u9ede\u89e3\u7528 wchar_t \u5514\u7528 char\uff0c\u662f\u56e0\u70ba\u8981\u8655\u7406\u4e2d\u6587\uff0cchar \u8981\u7528 UTF-8 \u7de8\u865f\u624d\u53ef\u653e\u975e\u82f1\u6587\u5b57\u5143\u3002\u5728\u8fd1\u4e4e\u5168\u4e2d\u6587\u4e0b\uff0cUTF-8 \u6bd4 UTF-16 \u4e0d\u4f46\u904b\u7b97\u6162\uff0c\u4e5f\u9700\u8981\u66f4\u591a\u5b58\u5132\u7a7a\u9593\u3002<\/p>\n<p>\u4e0b\u4e00\u6b65\u5c31\u662f\u628a program \u79fb\u690d\u5230 Linux\uff0c\u5beb\u5de6\u500b cmake script\uff0c\u7528 #define \u9694\u958b\u540c OS \u76f8\u95dc\u7684 API call\uff0c\u7576\u4e2d\u4e3b\u8981\u662f filesystem \u76f8\u95dc\u7684\u3002\u7d50\u679c\u5728 Linux compile \u7121\u554f\u984c\u4e86\uff0c\u4e4b\u5f8c implement \u8fd4\u5728 POSIX \u76f8\u61c9\u7684 functions \u4fbf\u53ef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6536\u5230\u4e00\u500b Win32 C++ program\uff0c\u767c\u89ba input \u5927 file \u6642\uff0c\u57f7\u884c\u9014\u4e2d\u6703\u639b\u6389\u3002\u67e5\u770b source code \u5f8c\u4f30\u8a08\u597d\u5927\u6a5f\u6703\u662f\u56e0\u70ba stack overflow\u3002 \u6539\u5de6\u5e7e\u53e5\uff0c\u628a wstring \u6539\u505a wchar_t \u53ca\u6539\u57cb\u76f8\u95dc\u7684 functions \u4fbf\u89e3\u6c7a\u4e86 stack overflow \u554f\u984c\u3002\u539f\u56e0\u662f\u300c\u65b0\u300dC++ STL \u662f\u6703\u628a\u77ed string \u653e stack\uff0c\u9577 string \u624d\u653e heap\uff0c\u5481\u505a\u662f\u70ba\u5de6 performance \u8003\u91cf\uff0c\u8981\u77e5\u9053 stack \u5feb\u904e heap \u597d\u591a\u3002\u4f46\u8d85\u5927\u91cf\u77ed string \u5c31\u6703\u505a\u6210 stack overflow\u3002\u7d50\u679c\u4fee\u6539\u5f8c\uff0c\u4fbf\u80fd\u6b63\u5e38\u904b\u884c\u3002 \u9ede\u89e3\u7528 wchar_t \u5514\u7528 char\uff0c\u662f\u56e0\u70ba\u8981\u8655\u7406\u4e2d\u6587\uff0cchar \u8981\u7528 UTF-8 \u7de8\u865f\u624d\u53ef\u653e\u975e\u82f1\u6587\u5b57\u5143\u3002\u5728\u8fd1\u4e4e\u5168\u4e2d\u6587\u4e0b\uff0cUTF-8 \u6bd4 UTF-16 \u4e0d\u4f46\u904b\u7b97\u6162\uff0c\u4e5f\u9700\u8981\u66f4\u591a\u5b58\u5132\u7a7a\u9593\u3002 \u4e0b\u4e00\u6b65\u5c31\u662f\u628a program \u79fb\u690d\u5230 Linux\uff0c\u5beb\u5de6\u500b\u2026 <span class=\"read-more\"><a href=\"https:\/\/carlos.aboutmy.info\/blog\/?p=567\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[15],"tags":[],"_links":{"self":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/567"}],"collection":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=567"}],"version-history":[{"count":1,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/567\/revisions"}],"predecessor-version":[{"id":568,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=\/wp\/v2\/posts\/567\/revisions\/568"}],"wp:attachment":[{"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carlos.aboutmy.info\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}