How will it new/allocate memory when a class have string-type members?

Z

zhengfish

HI,all
I have a class named CCC which have some members of std::string
type.
I declare a class pointer like this:
CCC* ccc = new CCC( xml_input );
then I send the ccc to another module with msg_queue.
then this lead to a error on win32 platform, but it's works well
on Redhat Linux 9.0.
what's the reason?

the error info on windows as follows:
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: E:\works\server\debug\configer.exe
File: dbgheap.c
Line: 1132

Expression: _CrtIsValidHeapPointer(pUserData)

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
 
S

Scott McPhillips [MVP]

zhengfish said:
HI,all
I have a class named CCC which have some members of std::string
type.
I declare a class pointer like this:
CCC* ccc = new CCC( xml_input );
then I send the ccc to another module with msg_queue.
then this lead to a error on win32 platform, but it's works well
on Redhat Linux 9.0.
what's the reason?

the error info on windows as follows:
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: E:\works\server\debug\configer.exe
File: dbgheap.c
Line: 1132

What is "another module"? If it is in a different process then the
address within the std::string is not valid outside of the process that
allocated it. If it is in a DLL then you could have multiple instances
of the crt memory manager. An address allocated by one manager (in exe)
cannot be passed to another manager (in DLL).
 
M

mlimber

zhengfish said:
HI,all
I have a class named CCC which have some members of std::string
type.
I declare a class pointer like this:
CCC* ccc = new CCC( xml_input );
then I send the ccc to another module with msg_queue.
then this lead to a error on win32 platform, but it's works well
on Redhat Linux 9.0.
what's the reason?

the error info on windows as follows:
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program: E:\works\server\debug\configer.exe
File: dbgheap.c
Line: 1132

Expression: _CrtIsValidHeapPointer(pUserData)

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

You should post this question on a Microsoft newsgroup since it is not
concerned with the standard language and libraries of C++ (the topic of
this group). Please see the FAQ for what is on- and off-topic here and
for some suggestions on the right place to post:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top