views:

137

answers:

1

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.

+1  A: 

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.

dash-tom-bang