<bdo id='TLDqT'></bdo><ul id='TLDqT'></ul>
  1. <tfoot id='TLDqT'></tfoot>

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

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

    1. 如何获取使用 malloc() 分配的内存块的大小?

      时间:2023-07-19

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

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

                问题描述

                可能的重复:
                我怎样才能得到来自 C 中指针的数组的大小?
                有吗有什么方法可以以编程方式确定 C++ 数组的大小?如果没有,为什么?

                我从一个 C 风格的函数中得到一个指向一块已分配内存的指针.现在,为了调试目的,知道如何big 这个指针指向的分配内存块.

                I get a pointer to a chunk of allocated memory out of a C style function. Now, it would be really interesting for debugging purposes to know how big the allocated memory block that this pointer points is.

                还有什么比盲目越界引发异常更优雅的事情吗?

                Is there anything more elegant than provoking an exception by blindly running over its boundaries?

                提前致谢,安德烈亚斯

                我在 Windows 上使用 VC++2005,在 Linux 上使用 GCC 4.3

                I use VC++2005 on Windows, and GCC 4.3 on Linux

                我在 VC++2005 下有 _msize不幸的是它在调试模式下导致异常......

                I have _msize under VC++2005 Unfortunately it results in an exception in debug mode....

                嗯.我已经尝试过我上面描述的方法,但它确实有效.至少在我调试并确保在通话后立即到图书馆出口我跑过缓冲区边界.很有魅力.

                Well. I have tried the way I described above with the exception, and it works. At least while I am debugging and ensuring that immediately after the call to the library exits I run over the buffer boundaries. Works like a charm.

                它只是不优雅,也无法在生产代码中使用.

                It just isn't elegant and in no way usable in production code.

                推荐答案

                这不是标准的,但如果你的库有一个 msize() 函数可以给你大小.

                It's not standard but if your library has a msize() function that will give you the size.

                一个常见的解决方案是用您自己的函数包装 malloc,该函数记录每个请求以及大小和结果内存范围,在发布版本中,您可以切换回真实"malloc.

                A common solution is to wrap malloc with your own function that logs each request along with the size and resulting memory range, in the release build you can switch back to the 'real' malloc.

                这篇关于如何获取使用 malloc() 分配的内存块的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:内存泄漏是“未定义的行为"吗?C++中的类问题? 下一篇:删除指向子类的指针是否调用基类析构函数?

                相关文章

                  <bdo id='CoibR'></bdo><ul id='CoibR'></ul>

              • <legend id='CoibR'><style id='CoibR'><dir id='CoibR'><q id='CoibR'></q></dir></style></legend>

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

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