Hi
1,Firstly, the “Out of memory” error is caused by ‘CMemoryException’ thrown at:
ReadWeatherStationFile()
--> m_AWS.Serialize(ar)
--> CObList::Serialize(CArchive& ar)
--> ar >> newData -- _AFX_INLINE CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb){ pOb = ar.ReadObject(NULL); return ar; }
--> CArchive::ReadObject(const CRuntimeClass* pClassRefRequested)
--> pOb = pClassRef ->CreateObject() //Fail to CreateObject here, pOb is null, so AfxThroMemoryException() is called.
2,Next, go further to investigate why “CreateObject()” is failed. In the Constructor of ‘WeatherStation’, CTime(1970,1,1,0,0,0) brings the original error. For CTime function itself, it’s OK to pass 1970,1,1,0,0,0 since the lower limit for the function is 1/1/1970 12:00:00 AM GMT, any time ranging from midnight, January 1, 1970 through December 31, 3000 Universal Coordinated Time (UTC) is OK. Whilst, CTime will call _mktime64, it is impacted by different time zones.
After an adjustment to UTC, _mktime32 handles dates from midnight, January 1, 1970, to 23:59:59 January 18, 2038, UTC. _mktime64 handles dates from midnight, January 1, 1970 to 23:59:59, December 31, 3000. This adjustment may cause these functions to return -1 (cast to time_t, __time32_t or __time64_t) even though the date you specify is within range. For example, if you are in Cairo, Egypt, which is two hours ahead of UTC, two hours will first be subtracted from the date you specify in timeptr; this may now put your date out of range.
3, Thus, you should determine the parameters of CTime by considering the time difference. For example, my time zone is UTC+8h, so I should call CTime(1970,1,1,8,0,0,0).
Modify the parameters of CTime by considering the time difference. For example, my time zone is UTC+8h, so I should call CTime(1970,1,1,8,0,0,0).
Then the m_time value returned by _mktime64 would be 0 rather than -1, the error would disappear, CreateObject() would success and then the Xyrix application can run successfully!
I suggest you could also try to use CTime(1970,1,2,0,0,0,0), and then deal with the time difference according to the time zone later.
Best Regards,
Jeanine
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hi
Many thanks for your response. Rebuilding is impractical for us at the moment. My app has ben shown to run on systems with 2Gb (albeit sluggish) and 4Gb. I just can't see why there should be any issue. I am having to test any theories over the internet.
Hi MiaWuMSFT,
Thank-you for your offer of assistance. You ask for the source files of my project. I would like to add that the application uses charting and serial third party software. Will the source code be sufficient for your needs?
Regards
you might have version mismatch. that is, your archived file is from an earlier version of the program. The author is supposed to bump the version number in IMPLEMENT_SERIAL when the data format changes, call CArchive::GetObjectSchema in the Serialize function if there are multiple versions of the data, and throw CArchiveException::badSchema when it encounters a version that it doesn't understand. Reading blindly without version checking could set a string's buffer length to a rather large unit that your memory can't handle.
Sign in to comment