CArchive and long*
-
Obviously you cannot serialize it in that format (it will only serialize the pointer, not the contents). What you need to do when saving your data is serialize the contents (for example, if this is an array of long, then serialize the number of elements and then serialize each element). Then, for loading, do the opposite operation: load the number of elements (and then allocate your array), then load each element.
Cédric Moonen Software developer
Charting control [v1.1] -
Obviously you cannot serialize it in that format (it will only serialize the pointer, not the contents). What you need to do when saving your data is serialize the contents (for example, if this is an array of long, then serialize the number of elements and then serialize each element). Then, for loading, do the opposite operation: load the number of elements (and then allocate your array), then load each element.
Cédric Moonen Software developer
Charting control [v1.1]I knew that it would not help me much to serialize the pointer to my long list. This is what i do:
void CMyObj::Serialize(CArchive& a)
{
if (ar.IsStoring())
{
ar<>m_nCount;
m_list = new long[m_nCount];
for(int i = 0;i>m_list[i];
}
}
}What am i doing wrong? m_nCount gets read corectly but m_list is always filled whith 0's :(
-
I knew that it would not help me much to serialize the pointer to my long list. This is what i do:
void CMyObj::Serialize(CArchive& a)
{
if (ar.IsStoring())
{
ar<>m_nCount;
m_list = new long[m_nCount];
for(int i = 0;i>m_list[i];
}
}
}What am i doing wrong? m_nCount gets read corectly but m_list is always filled whith 0's :(
eusto wrote:
What am i doing wrong? m_nCount gets read corectly but m_list is always filled whith 0's
This should work. Are you sure you are not writing an array of 0s? m_list is declared as a "long *"?
void CMyObj::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << m_nCount;
for(int i = 0; i < m_nCount; i++)
ar << m_list[i];
}
else
{
ar >> m_nCount;
m_list = new long[m_nCount];
for(int i = 0; i < m_nCount; i++)
{
ar >> m_list[i];
}
}
}