报告对象正在使用堆栈/堆上的内存量?(GDB)
Report how much memory on stack/heap is being used by an object? (GDB)
如何确定对象正在使用的内存总量,以及堆栈上当前存在的内存百分比是多少?那堆呢?
例如,给定此程序:
#include <cstdlib>
#include <vector>
#include <string>
int main(){
//I wonder how much memory is being
//used on the stack/heap right now.
std::vector<std::string> vec{"11","22","33"};
//how about now?
return EXIT_SUCCESS;
}
如何查看创建向量前后的堆栈和堆的大小?
这可以用GDB做到这一点吗?
该手册提供了一些关于检查记忆的信息,但我无法报告这些信息。
如果您准备使用 GLIBC 特定函数,则可以直接在程序中使用 mallinfo()
来回答以下问题:
#include <cstdlib>
#include <vector>
#include <string>
#include <iostream>
#include <malloc.h>
int main(){
std::cout << "Using: " << mallinfo().uordblks << "n";
std::vector<std::string> vec{"11","22","33"};
std::cout << "Using: " << mallinfo().uordblks << "n";
return EXIT_SUCCESS;
}
相关文章:
- 带有 GDB 调试器的 VS 代码内存视图
- 我对 gdb 内存地址有疑问
- GDB:在转储的整个内存中查找值
- GDB 无法访问值类型变量的内存
- 使用GDB并检查Data的内存布局
- GDB Python模块读取内存内容
- gdb矢量试图获取不在内存中的地址
- 使用GDB查找函数对应的内存地址/调试
- 与实际内存内容相比,GDB 内存检查输出偏差 8 个字节
- GDB:获取准确的内存地址,而不是<地址0x4越界>
- gdb:将内存地址强制转换为 STL 对象
- 如何在gdb中读取内存地址以进行i7处理器代码的反汇编
- 如何通过python从GDB中的内存地址中获取对象
- GDB:我如何找到加载符号(msymbols, psymbols, symbols)的内存总大小?
- Visual Studio 在 vmware 中使用 gcc/gdb 交叉编译 - >内存访问错误
- 为什么GDB中的一些内存地址看起来比其他的短
- 我怎么能看到一个c++类如何得到布局在内存与gdb
- 为什么这些内存值在GDB中永远不会改变
- 如何查看GDB中自动变量的内存地址
- 如何使用GDB来查找内存地址对应的函数