new[]分配的内存大小

发布于 2024-12-18 11:05:00 字数 1087 浏览 1 评论 0原文

我正在调查崩溃,并且我有以下堆栈跟踪,

...
12 4292e2c4 73148e89 KERNELBASE!RaiseException+0x58
13 4292e2fc 73150e7c MSVCR80!_CxxThrowException+0x46 [f:\dd\vctools\crt_bld\self_x86\crt\prebuild\eh\throw.cpp @ 161]
14 4292e318 386f21ba MSVCR80!operator new+0x69 [f:\dd\vctools\crt_bld\self_x86\crt\src\new.cpp @ 63]
15 4292e32c 386f1f39 StatEngineProxy!std::allocator<myClass>::allocate+0x1a [c:\program files (x86)\microsoft visual studio 8\vc\include\xmemory @ 146]
16 4292e384 386ef7e8 myModule!std::vector<myClass,std::allocator<myClass> >::_Insert_n+0xf9 [c:\program files (x86)\microsoft visual studio 8\vc\include\vector @ 1138]
17 4292e3b0 386ec20f myModule!std::vector<myClass,std::allocator<myClass> >::insert+0x88 [c:\program files (x86)\microsoft visual studio 8\vc\include\vector @ 855]
18 4292e3dc 3872bb17 myModule!std::vector<myClass,std::allocator<myClass> >::push_back+0xaf [c:\program files (x86)\microsoft visual studio 8\vc\include\vector @ 800]
....

原因很简单:bad_alloc。问题是我怎样才能找到 stl 试图分配多少内存。

I'm investigating a crash, and I have the stack trace below

...
12 4292e2c4 73148e89 KERNELBASE!RaiseException+0x58
13 4292e2fc 73150e7c MSVCR80!_CxxThrowException+0x46 [f:\dd\vctools\crt_bld\self_x86\crt\prebuild\eh\throw.cpp @ 161]
14 4292e318 386f21ba MSVCR80!operator new+0x69 [f:\dd\vctools\crt_bld\self_x86\crt\src\new.cpp @ 63]
15 4292e32c 386f1f39 StatEngineProxy!std::allocator<myClass>::allocate+0x1a [c:\program files (x86)\microsoft visual studio 8\vc\include\xmemory @ 146]
16 4292e384 386ef7e8 myModule!std::vector<myClass,std::allocator<myClass> >::_Insert_n+0xf9 [c:\program files (x86)\microsoft visual studio 8\vc\include\vector @ 1138]
17 4292e3b0 386ec20f myModule!std::vector<myClass,std::allocator<myClass> >::insert+0x88 [c:\program files (x86)\microsoft visual studio 8\vc\include\vector @ 855]
18 4292e3dc 3872bb17 myModule!std::vector<myClass,std::allocator<myClass> >::push_back+0xaf [c:\program files (x86)\microsoft visual studio 8\vc\include\vector @ 800]
....

cause is simple: bad_alloc. The question is how can I find how much memory stl was trying to alloc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

别理我 2024-12-25 11:05:00

try...catch 添加到该类中的所有 new[] 中,然后在 catch 子句中设置详细的调试信息。

Add try...catch to all your new[]'s in that class, and then set detailed debugging information inside the catch clause.

谁与争疯 2024-12-25 11:05:00

您可以为 STL 提供一个自定义分配器,这样它的所有内存声明都会通过您提供的函数。

这里有一个例子:
http://www.sjbrown.co。 uk/2004/05/01/pooled-allocators-for-the-stl/

You could give STL a custom allocator, so all its memory claims go through the functions you provide.

There's an example here:
http://www.sjbrown.co.uk/2004/05/01/pooled-allocators-for-the-stl/

长途伴 2024-12-25 11:05:00

简单的。您可以获得 CRT 的源代码。 (可能位于 C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\new.cpp 中)。因此,您可以查看第 14 帧的源代码和变量,

您会发现第 58 行看起来像 void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc)。该参数 size 就是您要查找的参数。

Simple. You get the sources for the CRT. (Probably in C:\Program Files\Microsoft Visual Studio 10.0\VC\crt\src\new.cpp). Therefore, you can view the source and variables for frame 14

You'll find that line 58 looks like void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc). That argument size is the one you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文