473,320 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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)

Nov 22 '05 #1
2 1766
zhengfish wrote:
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).

--
Scott McPhillips [VC++ MVP]

Nov 22 '05 #2
zhengfish wrote:
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-lit...t.html#faq-5.9

Cheers! --M

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Curt | last post by:
If this is the complete program (ie, the address of the const is never taken, only its value used) is it likely the compiler will allocate ram for constantA or constantB? Or simply substitute the...
4
by: Alan Gifford | last post by:
I wrote a program to make sure that new would throw a bad_alloc exception if more memory was requested than was available. On my system, new allocates up to 2931 MBs of memory (I don't have that...
5
by: Alfonso Morra | last post by:
Hi, Doest the c_str() method of the string class allocate memory. if it does alloc mem behind the scenes - whose responsibility is it to cleanup after (i.e. free the returned char*?) Tkx
12
by: gc | last post by:
I am writing a function that given nx1 vector a and a nx1 b solves a system of equations f(a,c)=b for a nx1 c. While writing the function: 1] Should I allocate the memory for c within the...
29
by: keredil | last post by:
Hi, Will the memory allocated by malloc get released when program exits? I guess it will since when the program exits, the OS will free all the memory (global, stack, heap) used by this...
7
by: Michael | last post by:
Hi, What's the benefit to dynamically allocate memory? using namespace std; int main() { char* ptr; ptr="abc";
11
by: lylone | last post by:
Some doubt appeared by chance.When i compiled it with vc7.1 and run it on windows,the "string" constructed in class destructed follow the class, but when i compiled it with g++/gcc and run it on...
2
by: lovecreatesbea... | last post by:
If the built-in operator keyword new doesn't allocate memory on heap and it calls global operator new (::operator new) or class member operator new to do that. What are the two kinds of operator...
66
by: karthikbalaguru | last post by:
Hi, Will 'free' return the memory Immediately to the OS ? Thx in advans, Karthik Balaguru
15
by: asm23 | last post by:
Hi, everyone, I'm studying the <<Thinking in C++>volume Two. In Chapter One, the example code : Auto_ptr.cpp //------------------------------------------------------- #include <memory> #include...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.