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.