{"id":107,"date":"2021-08-28T19:26:29","date_gmt":"2021-08-28T11:26:29","guid":{"rendered":"http:\/\/139.224.63.49\/?p=107"},"modified":"2021-08-28T19:26:29","modified_gmt":"2021-08-28T11:26:29","slug":"%e7%94%b1c-string-%e5%bc%95%e5%8f%91%e7%9a%84%e6%80%a7%e8%83%bd%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/iamnear.top\/?p=107","title":{"rendered":"\u7531c# string += \u5f15\u53d1\u7684\u6027\u80fd\u95ee\u9898"},"content":{"rendered":"\n<p>\u540c\u5b66\u8ba9\u5e2e\u5fd9\u8c03\u8bd5\u4e00\u4e2a\u7a0b\u5e8f\u3002\u7a0b\u5e8f\u4e3b\u4f53\u662f\u4e00\u4e2a\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u5f0f\u3002\u751f\u4ea7\u8005\u4e0d\u65ad\u76d1\u542c\u6307\u5b9a\u7aef\u53e3\u4e0a\u7684udp\u6d88\u606f\uff0c\u6536\u5230\u6d88\u606f\u5c31\u653e\u5230\u6d88\u606f\u961f\u5217\u3002\u5de5\u4f5c\u7ebf\u7a0b\u5219\u8d1f\u8d23\u5904\u7406\u6d88\u606f\u961f\u5217\u4e2d\u7684\u6d88\u606f\u3002\u95ee\u9898\u662f\u901a\u8fc7\u8bb0\u5f55\u4e0b\u6765\u7684\u65f6\u95f4\u6765\u770b\uff0c\u4ece\u6536\u5230\u6d88\u606f\u5230\u6d88\u606f\u88ab\u5904\u7406\u65f6\u95f4\u8fc7\u53bb\u4e86\u51e0\u767e\u6beb\u79d2\u3002<\/p>\n\n\n\n<p>\u6211\u9996\u5148\u6539\u4e86\u4e0b\u4e00\u4e9b\u591a\u7ebf\u7a0b\u4e2d\u9700\u8981\u6ce8\u610f\u7684\u540c\u6b65\u4e8b\u9879\u3002\u6bd4\u5982\u5bf9\u4e8e\u53d8\u91cf\u7684\u4fee\u6539\uff0c\u8981\u52a0\u9501\u6216\u8005Interlocked\u3002<\/p>\n\n\n\n<p>c#\u4e2d\u6709\u4e00\u70b9\u8981\u6ce8\u610f\u7684\uff0c\u548cc++\u4e0d\u540c\uff0cc#\u4e2d\u7684AutoResetEvent\u867d\u7136\u548cc++\u4e2d\u7684condition_variable\u7c7b\u4f3c\uff0c\u4f46\u662fc++\u4e2d\u7684condition_vairable\u662f\u5728lock\u5757\u5185\u6267\u884c\u7684\uff0c\u5f53sleep\u7684\u65f6\u5019\u4f1a\u81ea\u52a8\u91ca\u653e\u9501\uff0c\u5524\u9192\u7684\u65f6\u5019\u4f1a\u81ea\u52a8\u52a0\u9501\u3002\u4f46\u662fc#\u4e2d\u7684AutoResetEvent\u5219\u4e0d\u662f\u8fd9\u4e2a\u903b\u8f91\uff0c\u8fd9\u4e2a\u548c\u9501\u65e0\u5173\uff0c\u4e0d\u9700\u8981\u653e\u5230lock\u5757\u5185\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u7528jetbrain\u516c\u53f8\u7684vs resharp\u63d2\u4ef6\u6765\u505aprofile\uff0c\u6536\u96c6\u597d\u6570\u636e\u4ee5\u540e\u7528dottrace\u6253\u5f00\u3002\u901a\u8fc7\u5206\u6790\u5de5\u4f5c\u7ebf\u7a0b\u7684cpu\u6267\u884c\u60c5\u51b5\uff0c\u53d1\u73b0\u5de5\u4f5c\u7ebf\u7a0b\u662f\u6ee1\u8d1f\u8377\u7684\uff0c\u6240\u4ee5\u5e94\u8be5\u4e0d\u662f\u7531\u4e8e\u6b7b\u9501\u6216\u8005\u9501\u7ade\u4e89\u5bfc\u81f4\u7684\u5ef6\u65f6\u3002\u8fdb\u4e00\u6b65\u53d1\u73b0\uff0c\u5de5\u4f5c\u7ebf\u7a0b99.9%\u7684\u65f6\u95f4\u90fd\u82b1\u5728\u4e00\u4e2a\u53eb\u505abytetohexstr\u7684\u51fd\u6570\u4e0a\u3002\u8fd9\u4e2a\u51fd\u6570\u987e\u540d\u601d\u4e49\uff0c\u5c31\u662f\u628a\u7c7b\u4f3c\\x11\\x22\u7684bytes\u6570\u7ec4\u8f6c\u4e3a\u201d1122\u201c\u8fd9\u6837\u7684string<\/p>\n\n\n\n<p>\u90a3\u4e48\u8fd9\u4e2a\u51fd\u6570\u662f\u600e\u4e48\u5199\u7684\u5462\uff1f\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        public string bytetohexstr(byte&#91;] bytes, int length)     \/\/\u5b57\u8282\u8f6c\u5316\u4e3a\u4e8c\u8fdb\u5236\n        {\n            string returnstr = \"\";\n            if (bytes != null)\n            {\n                for (int i = 0; i &lt; length; i++)\n                {\n                    returnstr += bytes&#91;i].ToString(\"X2\");\n                }\n            }\n            return returnstr;\n        }<\/code><\/pre>\n\n\n\n<p>\u770b\u5230\u8fd9\u95ee\u9898\u5c31\u5f88\u660e\u663e\u4e86\uff0c\u7531\u4e8ec#\u4e2dstring\u662f\u4e0d\u53ef\u53d8\u5bf9\u8c61\uff0c\u6bcf\u6b21+=\u90fd\u8981\u5206\u914d\u5185\u5b58\u7ed9\u4e00\u4e2a\u65b0\u5bf9\u8c61\uff0c\u5e76\u4e14\u628astring\u7684\u5185\u5bb9\u62fc\u63a5\u590d\u5236\u5230\u65b0\u5bf9\u8c61\u3002\u8fd9\u6837\u8fd9\u4e2a\u51fd\u6570\u5728\u5185\u5b58\u5c42\u9762\u4e0a\u5176\u5b9e\u662f\u4e2aO\uff08n^2\uff09\u7ea7\u522b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u3002\u540c\u65f6\u5927\u91cf\u4e34\u65f6\u5bf9\u8c61\u7684\u4ea7\u751f\uff0c\u4e5f\u52a0\u91cd\u4e86gc\u7684\u538b\u529b\u3002<\/p>\n\n\n\n<p>\u6211\u628a\u8fd9\u4e2a\u51fd\u6570\u6539\u6210\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    public string bytetohexstr(byte&#91;] bytes, int length)     \/\/\u5b57\u8282\u8f6c\u5316\u4e3a\u4e8c\u8fdb\u5236\n    {\n        if (bytes == null)\n            return \"\";\n        char&#91;] r = new char&#91;2 * length];\n        for(int i=0;i&lt;length;i++)\n        {\n            int high = bytes&#91;i] \/ 16;\n            int low = bytes&#91;i] % 16;\n            r&#91;i*2] = idx_to_hex&#91;high];\n            r&#91;i*2 + 1] = idx_to_hex&#91;low];\n        }\n        string ret = new string(r);\n        return ret;\n    }<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a\u6211\u5bf9c#\u4e0d\u662f\u5f88\u719f\u6089\uff0c\u540e\u6765\u53d1\u73b0\u7528c#\u4e2d\u7684stirnbuilder\u5e94\u8be5\u6548\u679c\u4e5f\u5dee\u4e0d\u591a\u3002<\/p>\n\n\n\n<p>\u518d\u8c03\u8bd5\u53d1\u73b0\u7a0b\u5e8f\u4e00\u4e0b\u5b50\u98de\u5feb\uff0c\u6839\u636eprofile\u7684\u7ed3\u679c\uff0c\u56db\u4e2a\u7ebf\u7a0b\u5904\u7406\u5341\u4e2a\u6d88\u606f\uff0c\u53ea\u9700\u8981\u4e0d\u52300.7ms\u3002<\/p>\n\n\n\n<p>\u8003\u8651\u5230\u6839\u636eprofile\u7684\u7ed3\u679c\uff0c\u6ca1\u5fc5\u8981\u8fd9\u4e48\u591a\u7ebf\u7a0b\uff0c\u6211\u5c31\u6539\u6210\u4e86\u4e00\u4e2a\u751f\u4ea7\u8005\uff0c\u4e00\u4e2a\u6d88\u8d39\u8005\u7684\u6a21\u5f0f\uff0c\u6d4b\u8bd5\u4e0b\u6765\u6548\u679c\u4e5f\u5f88\u597d\uff0c\u6bcf\u6b21\u5904\u740610\u4e2a\u6d88\u606f\u90fd\u57281ms\u4ee5\u5185\u3002<\/p>\n\n\n\n<p>\u8fd9\u6b21\u8c03\u8bd5\u8c03\u8bd5\u8ba9\u6211\u611f\u53d7\u5230\u4ee3\u7801\u4e0d\u6ce8\u610f\u7684\u8bdd\uff0c\u6548\u7387\u771f\u7684\u53ef\u80fd\u4f1a\u76f8\u5dee\u5343\u500d\u4e43\u81f3\u5b8c\u5907\u3002\u8fd9\u4e2a\u51fd\u6570\u7684\u8f93\u5165\u5b57\u8282\u4e00\u822c\u662f\u4e24\u5343\u591a\uff0c\u6309\u7167\u539f\u6765\u90a3\u79cd\u5199\u6cd5\u5f97\u67092000*2000\/2 = 2million\u7684\u5185\u5b58\u5199\u5165\uff0c\u8fd9\u8fd8\u6ca1\u7b97\u4e0d\u65ad\u7533\u8bf7\u5c0f\u5185\u5b58\u4ee5\u53ca\u91ca\u653e\u5185\u5b58\u6d88\u8017\u7684\u65f6\u95f4\u3002\u800c\u4fee\u6539\u8fc7\u7684\u4ee3\u7801\uff0c\u5185\u5b58\u5199\u5165\u53ea\u67092000\u6b21\uff0c\u6548\u7387\u76f8\u5dee\u4e00\u5343\u500d\u3002\u6240\u4ee5\u9020\u6210\u51e0\u767e\u6beb\u79d2\u548c\u96f6\u70b9\u51e0\u6beb\u79d2\u7684\u6781\u7aef\u5dee\u8ddd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u5b66\u8ba9\u5e2e\u5fd9\u8c03\u8bd5\u4e00\u4e2a\u7a0b\u5e8f\u3002\u7a0b\u5e8f\u4e3b\u4f53\u662f\u4e00\u4e2a\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u5f0f\u3002\u751f\u4ea7\u8005\u4e0d\u65ad\u76d1\u542c\u6307\u5b9a\u7aef\u53e3\u4e0a\u7684udp\u6d88\u606f\uff0c\u6536\u5230\u6d88&hellip; <a href=\"http:\/\/iamnear.top\/?p=107\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u7531c# string += \u5f15\u53d1\u7684\u6027\u80fd\u95ee\u9898<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":{"0":"post-107","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-c_sharp","7":"h-entry","9":"h-as-article"},"_links":{"self":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=107"}],"version-history":[{"count":1,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":108,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions\/108"}],"wp:attachment":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}