如何判断 CString 是在堆还是堆栈上分配内存?
如何判断 MFC CString 是在堆还是堆栈上分配内存?我正在针对 Windows Mobile/Windows CE 平台进行编译。
我正在开发一个由其他人开发的项目,并且我在某些情况下目睹了堆栈溢出。我试图弄清楚在堆栈上分配的自定义 SQLite 记录集类(具有许多 CString 成员变量)是否导致堆栈溢出。
How can I tell if the MFC CString allocates memory on the heap or stack? I am compiling for the Windows Mobile/Windows CE platform.
I am working on a project developed by someone else and I have witnessed stack overflows under certain circumstances. I am trying to figure out if the custom SQLite recordset classes (with many CString member variables) allocated on the stack are causing the stack overflows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将一个对象放入包含“许多”CString 的堆栈中,那么您将在堆栈上有一些数据,在堆上有一些数据。
CString“管理”数据就是对象本身。 sizeof(CString) 会告诉你它有多大。它包括有关其大小和指向实际字符数组的指针的信息。字符数组本身是从堆中获取的。 CString::GetLength() 或任何调用都会告诉您堆上占用了多少空间。
sizeof(YourCustomRecordset) 将告诉您将对象放入堆栈时它占用了多少堆栈空间。
If you're putting an object onto the stack that contains "many" CStrings, you'll have some data on the stack and some on the heap.
The CString "management" data is what the object itself is. sizeof(CString) will tell you how big it is. It includes information about its size and the pointer to the actually character array. The character array itself is taken from the heap. CString::GetLength() or whatever the call is will tell you how much space is taken on the heap.
sizeof(YourCustomRecordset) will tell you how much stack space is taken up by your object when you put it on the stack.