久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <bdo id='47Slm'></bdo><ul id='47Slm'></ul>
    <legend id='47Slm'><style id='47Slm'><dir id='47Slm'><q id='47Slm'></q></dir></style></legend>
      <tfoot id='47Slm'></tfoot>

    1. <i id='47Slm'><tr id='47Slm'><dt id='47Slm'><q id='47Slm'><span id='47Slm'><b id='47Slm'><form id='47Slm'><ins id='47Slm'></ins><ul id='47Slm'></ul><sub id='47Slm'></sub></form><legend id='47Slm'></legend><bdo id='47Slm'><pre id='47Slm'><center id='47Slm'></center></pre></bdo></b><th id='47Slm'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='47Slm'><tfoot id='47Slm'></tfoot><dl id='47Slm'><fieldset id='47Slm'></fieldset></dl></div>

    2. <small id='47Slm'></small><noframes id='47Slm'>

    3. 使用 std::basic_string&lt;t&gt; 是否合理?作為目

      Is it reasonable to use std::basic_stringlt;tgt; as a contiguous buffer when targeting C++03?(使用 std::basic_stringlt;tgt; 是否合理?作為目標 C++03 時的連續緩沖區?)
          <bdo id='uY5ef'></bdo><ul id='uY5ef'></ul>
          <tfoot id='uY5ef'></tfoot>

          <small id='uY5ef'></small><noframes id='uY5ef'>

        • <i id='uY5ef'><tr id='uY5ef'><dt id='uY5ef'><q id='uY5ef'><span id='uY5ef'><b id='uY5ef'><form id='uY5ef'><ins id='uY5ef'></ins><ul id='uY5ef'></ul><sub id='uY5ef'></sub></form><legend id='uY5ef'></legend><bdo id='uY5ef'><pre id='uY5ef'><center id='uY5ef'></center></pre></bdo></b><th id='uY5ef'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uY5ef'><tfoot id='uY5ef'></tfoot><dl id='uY5ef'><fieldset id='uY5ef'></fieldset></dl></div>
            <tbody id='uY5ef'></tbody>
          <legend id='uY5ef'><style id='uY5ef'><dir id='uY5ef'><q id='uY5ef'></q></dir></style></legend>

                本文介紹了使用 std::basic_string&lt;t&gt; 是否合理?作為目標 C++03 時的連續緩沖區?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我知道在 C++03 中,從技術上講,std::basic_string 模板不需要具有連續內存.但是,我很好奇有多少現代編譯器真正利用了這種自由的實現.例如,如果想使用 basic_string 來接收某些 C API 的結果(如下例所示),分配一個向量只是為了立即將其轉換為字符串似乎很愚蠢.

                I know that in C++03, technically the std::basic_string template is not required to have contiguous memory. However, I'm curious how many implementations exist for modern compilers that actually take advantage of this freedom. For example, if one wants to use basic_string to receive the results of some C API (like the example below), it seems silly to allocate a vector just to turn it into a string immediately.

                示例:

                DWORD valueLength = 0;
                DWORD type;
                LONG errorCheck = RegQueryValueExW(
                        hWin32,
                        value.c_str(),
                        NULL,
                        &type,
                        NULL,
                        &valueLength);
                
                if (errorCheck != ERROR_SUCCESS)
                    WindowsApiException::Throw(errorCheck);
                else if (valueLength == 0)
                    return std::wstring();
                
                std::wstring buffer;
                do
                {
                    buffer.resize(valueLength/sizeof(wchar_t));
                    errorCheck = RegQueryValueExW(
                            hWin32,
                            value.c_str(),
                            NULL,
                            &type,
                            &buffer[0],
                            &valueLength);
                } while (errorCheck == ERROR_MORE_DATA);
                
                if (errorCheck != ERROR_SUCCESS)
                    WindowsApiException::Throw(errorCheck);
                
                return buffer;
                

                我知道這樣的代碼可能會稍微降低可移植性,因為它意味著 std::wstring 是連續的——但我想知道這段代碼是多么不可移植.換句話說,編譯器如何真正利用非連續內存所允許的自由?

                I know code like this might slightly reduce portability because it implies that std::wstring is contiguous -- but I'm wondering just how unportable that makes this code. Put another way, how may compilers actually take advantage of the freedom having noncontiguous memory allows?

                我更新了這個問題以提及 C++03.讀者應該注意,當以 C++11 為目標時,標準現在要求 basic_string 是連續的,因此當以該標準為目標時,上述問題不是問題.

                I updated this question to mention C++03. Readers should note that when targeting C++11, the standard now requires that basic_string be contiguous, so the above question is a non issue when targeting that standard.

                推薦答案

                我認為假設 std::string 連續分配其存儲空間是非常安全的.

                I'd consider it quite safe to assume that std::string allocates its storage contiguously.

                目前,std::string 的所有已知實現都是連續分配空間的.

                At the present time, all known implementations of std::string allocate space contiguously.

                此外,C++ 0x (N3000) 要求連續分配空間(第 21.4.1/5 節):

                Moreover, the current draft of C++ 0x (N3000) requires that the space be allocated contiguously (§21.4.1/5):

                在一個類似字符的對象應存儲 basic_string 對象連續.也就是說,對于任意basic_string 對象 s,身份&*(s.begin() + n) == &*s.begin() + n應適用于 n 的所有值,這樣0 <= n

                The char-like objects in a basic_string object shall be stored contiguously. That is, for any basic_string object s, the identity &*(s.begin() + n) == &*s.begin() + n shall hold for all values of n such that 0 <= n < s.size().

                因此,std::string 當前或未來實現使用非連續存儲的可能性基本上為零.

                As such, the chances of a current or future implementation of std::string using non-contiguous storage are essentially nil.

                這篇關于使用 std::basic_string&lt;t&gt; 是否合理?作為目標 C++03 時的連續緩沖區?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                Scope of exception object in C++(C++中異常對象的范圍)
                Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)

                1. <i id='FxESc'><tr id='FxESc'><dt id='FxESc'><q id='FxESc'><span id='FxESc'><b id='FxESc'><form id='FxESc'><ins id='FxESc'></ins><ul id='FxESc'></ul><sub id='FxESc'></sub></form><legend id='FxESc'></legend><bdo id='FxESc'><pre id='FxESc'><center id='FxESc'></center></pre></bdo></b><th id='FxESc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FxESc'><tfoot id='FxESc'></tfoot><dl id='FxESc'><fieldset id='FxESc'></fieldset></dl></div>
                      <bdo id='FxESc'></bdo><ul id='FxESc'></ul>
                    • <small id='FxESc'></small><noframes id='FxESc'>

                        <tbody id='FxESc'></tbody>

                        <legend id='FxESc'><style id='FxESc'><dir id='FxESc'><q id='FxESc'></q></dir></style></legend>

                        • <tfoot id='FxESc'></tfoot>
                          主站蜘蛛池模板: 欧美二区在线 | 成人免费毛片片v | 欧美日韩亚 | 中文字幕一区二区三区精彩视频 | 欧美久久一区 | 日本中出视频 | 午夜久久久 | 色综合天天天天做夜夜夜夜做 | 成人精品| yeyeav| 日日噜噜噜夜夜爽爽狠狠视频97 | 成人免费共享视频 | 日本一区视频在线观看 | 四虎在线观看 | 久久久精品一区 | 国产一区二区欧美 | 一本色道精品久久一区二区三区 | 欧美成人a | 欧美日韩一区二区三区四区 | 亚洲国产成人精品在线 | 国产亚洲精品一区二区三区 | 中文字幕乱码一区二区三区 | 五月婷婷 六月丁香 | 久产久精国产品 | 国产精品日日摸夜夜添夜夜av | 国产一区在线看 | 亚洲精品在线免费 | 亚洲人成在线播放 | 日本亚洲欧美 | 欧美精品久久久久久 | 久久精品99国产精品日本 | 五月天婷婷久久 | 毛片免费看 | 亚洲福利一区二区 | 人人人人人爽 | 久久免费高清 | 黄色片网此 | 国产成人精品一区二区三区网站观看 | 日本黄色大片免费 | 日韩在线免费 | 久久99这里只有精品 |