1. <i id='kQCpr'><tr id='kQCpr'><dt id='kQCpr'><q id='kQCpr'><span id='kQCpr'><b id='kQCpr'><form id='kQCpr'><ins id='kQCpr'></ins><ul id='kQCpr'></ul><sub id='kQCpr'></sub></form><legend id='kQCpr'></legend><bdo id='kQCpr'><pre id='kQCpr'><center id='kQCpr'></center></pre></bdo></b><th id='kQCpr'></th></span></q></dt></tr></i><div id='kQCpr'><tfoot id='kQCpr'></tfoot><dl id='kQCpr'><fieldset id='kQCpr'></fieldset></dl></div>
    2. <tfoot id='kQCpr'></tfoot>
      <legend id='kQCpr'><style id='kQCpr'><dir id='kQCpr'><q id='kQCpr'></q></dir></style></legend>
        <bdo id='kQCpr'></bdo><ul id='kQCpr'></ul>

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

        如何找到任何对象使用的内存

        How to find the memory used by any object(如何找到任何对象使用的内存)

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

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

          <tbody id='AwQ5q'></tbody>

                <bdo id='AwQ5q'></bdo><ul id='AwQ5q'></ul>
                <i id='AwQ5q'><tr id='AwQ5q'><dt id='AwQ5q'><q id='AwQ5q'><span id='AwQ5q'><b id='AwQ5q'><form id='AwQ5q'><ins id='AwQ5q'></ins><ul id='AwQ5q'></ul><sub id='AwQ5q'></sub></form><legend id='AwQ5q'></legend><bdo id='AwQ5q'><pre id='AwQ5q'><center id='AwQ5q'></center></pre></bdo></b><th id='AwQ5q'></th></span></q></dt></tr></i><div id='AwQ5q'><tfoot id='AwQ5q'></tfoot><dl id='AwQ5q'><fieldset id='AwQ5q'></fieldset></dl></div>
                <tfoot id='AwQ5q'></tfoot>
                  本文介绍了如何找到任何对象使用的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  class Help
                  {
                  public:
                          Help();
                          ~Help();
                  
                          typedef std::set<string> Terms;
                          typedef std::map<string, std::pair<int,Terms> > TermMap;
                          typedef std::multimap<int, string, greater<int> > TermsMap;
                  
                  private:
                  
                          TermMap  terms;
                          TermsMap    termsMap;
                  };
                  

                  我们如何找到termtermsMap 对象使用的内存(以字节为单位).我们有图书馆吗?

                  How can we find the memory used (in bytes) by the objects term and termsMap. Do we have any library ?

                  推荐答案

                  如果您正在寻找对象的完整内存使用情况,这在 C++ 中通常无法解决 - 而我们可以获得实例的大小通过 sizeof() 自身,对象总是可以根据需要动态分配内存.

                  If you are looking for the full memory usage of an object, this can't be solved in general in C++ - while we can get the size of an instance itself via sizeof(), the object can always allocate memory dynamically as needed.

                  如果你能找出一个容器中单个元素有多大,你就可以得到一个下限:

                  If you can find out how big the individual element in a container are, you can get a lower bound:

                  size = sizeof(map<type>) + sum_of_element_sizes;
                  

                  请记住,容器仍然可以分配额外的内存作为实现细节,对于像 vectorstring 这样的容器,您必须检查 分配大小.

                  Keep in mind though that the containers can still allocate additional memory as an implementation detail and that for containers like vector and string you have to check for the allocated size.

                  这篇关于如何找到任何对象使用的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                1. <small id='b4HPE'></small><noframes id='b4HPE'>

                    <tbody id='b4HPE'></tbody>
                  <legend id='b4HPE'><style id='b4HPE'><dir id='b4HPE'><q id='b4HPE'></q></dir></style></legend>

                    • <tfoot id='b4HPE'></tfoot>
                        • <bdo id='b4HPE'></bdo><ul id='b4HPE'></ul>
                          <i id='b4HPE'><tr id='b4HPE'><dt id='b4HPE'><q id='b4HPE'><span id='b4HPE'><b id='b4HPE'><form id='b4HPE'><ins id='b4HPE'></ins><ul id='b4HPE'></ul><sub id='b4HPE'></sub></form><legend id='b4HPE'></legend><bdo id='b4HPE'><pre id='b4HPE'><center id='b4HPE'></center></pre></bdo></b><th id='b4HPE'></th></span></q></dt></tr></i><div id='b4HPE'><tfoot id='b4HPE'></tfoot><dl id='b4HPE'><fieldset id='b4HPE'></fieldset></dl></div>