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

Discussion in 'C++' started by zhengfish, Nov 18, 2005.

  1. zhengfish

    zhengfish Guest

    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)
     
    zhengfish, Nov 18, 2005
    #1
    1. Advertising

  2. Re: How will it new/allocate memory when a class have string-typemembers?

    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]
     
    Scott McPhillips [MVP], Nov 18, 2005
    #2
    1. Advertising

  3. zhengfish

    mlimber Guest

    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-lite/how-to-post.html#faq-5.9

    Cheers! --M
     
    mlimber, Nov 18, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Gifford
    Replies:
    4
    Views:
    397
    tom_usenet
    Oct 27, 2003
  2. CoolPint
    Replies:
    8
    Views:
    1,001
    Jeff Schwab
    Dec 14, 2003
  3. Bryan Parkoff

    new -- allocate memory question

    Bryan Parkoff, Apr 5, 2005, in forum: C++
    Replies:
    1
    Views:
    430
    Alf P. Steinbach
    Apr 5, 2005
  4. Alfonso Morra
    Replies:
    5
    Views:
    461
    Mike Wahler
    Sep 28, 2005
  5. Replies:
    2
    Views:
    327
    benben
    Nov 26, 2006
Loading...

Share This Page