C and C++
Serialization produces memory fault -- even in this TINY class!
: compile for debug and put a breakpoint in that SerializeObject() function to see if its actualy getting called or not. I think the parameters to it have to be identical to how you created the CList object in the first place. Of course the alternative is not to use the Serialize method of that CList template, but to do your own thing.
I did, the function is not called, never.
What I recognized though is that a little question mark appears on the breakpoint when compiling for debug. What does that mean? Perhaps the compiler ignores my function? I'm using Visual C++ 7.
: I did, the function is not called, never.
[blue]That means you have defined it incorrectly.[/blue]
: What I recognized though is that a little question mark appears on the breakpoint when compiling for debug. What does that mean? Perhaps the compiler ignores my function? I'm using Visual C++ 7.
[blue]I can't help you with the ? question -- I don't have that compiler. I use VC 6.[/blue]
[b][red]This message was edited by __c4.ep at 2003-5-21 12:35:8[/red][/b][hr]
: : I did, the function is not called, never.
: [blue]That means you have defined it incorrectly.[/blue]
template <> void AFXAPI SerializeElements ( CArchive& ar, CSkill* pElement, int nCount )
for ( int i = 0; i < nCount; i++, pElement++ )
pElement->Serialize( ar );
whereas CSkill is the class which objects are being hold in the list. I defined the function at the very top of the cpp file, even before any includes occur. Otherwise I would get said error.
What's wrong with the definition? CSkill::Serialize() is of course defined as well, but -- obviously -- not called either.
: template <> void AFXAPI SerializeElements ( CArchive& ar, CSkill* pElement, int nCount )
: for ( int i = 0; i < nCount; i++, pElement++ )
: pElement->Serialize( ar );
did you declare the CList object like this?
: did you declare the CList object like this?
: CList list;
No, like this:
See the example in the private e-mail I sent you last night. That should solve your problem. Let me know if you didn't get it.
: See the example in the private e-mail I sent you last night. That should solve your problem. Let me know if you didn't get it.
Yeah I got it and already sent you an answer.
Actually I do it pretty much the same, just that I always get those errors when defining the template function SerializeElements().
Btw, why do you use the CArchive Read/Write functions instead of the streaming operators?
: Btw, why do you use the CArchive Read/Write functions instead of the streaming operators?
habit. I had some problems once reading back CString. Also, I work with UNICODE (English language only) a great deal and the stream operators produce different file format.
: : Btw, why do you use the CArchive Read/Write functions instead of the streaming operators?
: habit. I had some problems once reading back CString. Also, I work with UNICODE (English language only) a great deal and the stream operators produce different file format.
Ah ok, good to know.
Do you have any idea why i'm getting those errors when defining SerializeElements() as described above? Weird eh?
: Do you have any idea why i'm getting those errors when defining SerializeElements() as described above? Weird eh?
No, I don't know. But I'm not really all that good with templates anyway. Post that question on www.codeguru.com -- they have several members that are pretty darned good at it.
: [b][red]This message was edited by __c4.ep at 2003-5-20 7:37:21[/red][/b][hr]
: Alright, I've tried everything over the last 5 hours, but I just can't get this code to work.
: What I want to do is to serialize a class in an SDI app (created with app wizard), which holds a list of another class holding a CString object. Here's the code:
: // header
: class COther
: CString m_str;
: class CData
: void Serialize( CArchive& ar )
: m_list.Serialize( ar );
: CList m_list;
: Then I instantiate CData in CSerializationDoc and add an object of COther to the list in CSerializationDoc's ctor:
: // TODO: add one-time construction code here
: COther obj;
: obj.m_str = "Text";
: m_data.m_list.AddTail( obj );
: Then I finally have my Serialization func:
: void CSerializationDoc::Serialize(CArchive& ar)
: m_data.Serialize( ar );
: Well, if I run this app and load a document, I'm getting memory faults when exiting the app. The errors occur in CStringData::Release().
: Obviously, the app tries to release a CString which already HAS been released, thus trying to delete data where nothing is anymore.
: Does anyone know what the heck is going wrong here?
: I have already posted two times on codeguru.com but noone can help me there. Perhaps you can?
: Hi there, i've had exactly the same problem as you have..i wanted to save a sting by using serialization. I'm nog at home right know, but when i do, i'll send you my solution.. i can remember it had something do to with the CString object that wast created or something.
It looks like you're new here. If you want to get involved, click one of these buttons!
Assembly Code Share
Getting started in assembly
C and C++
C/C++ on Linux/Unix
C/C++ Windows API
C++ Game Development
Delphi and Kylix
Java Server Pages
Access databases and VB
Advance Visual Basic
DirectX Game dev
Newbie Game Programmers
Cooling & Overclocking
Database & SQL
Sound & Music
FreeLance Software City
C# & VB.NET School Support
Join the Team
Comments on this site
New programming languages
Off topic board
Mobile & Wireless
Operating Systems & Platforms
Witsbits Go Cloud
Embedded / RTOS
Windows CE & Pocket PC
Networking And Security
Windows 2003 Server
RUP & UML
Quality & Testing
Active Server Pages
HTML & WEB-Design
Mobile Internet & Messaging
WEB-Services / SOAP
In this Discussion