View Single Post
  #3   (View Single Post)  
Old 23rd October 2009
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,303
Default

Quote:
Originally Posted by robbak View Post
I still cannot believe that this is a good thing - I mean, the class is overwriting itself!
From the information provided, the class is simply a repository for data (& the data is composed of fundamental types, no user-defined types...) -- no inheritance or virtual member functions are involved. Because of this scenario, this most likely points to the beginning of data, so the problem decomposes down to how one dumps/restores a struct. You may want to confirm this to yourself by looking at the address of this & compare to the address of the first member.

If the class structure involved inheritance, this would point to the vtable which would change from one instance of the application to the next. Writing to disk wouldn't be a problem, but restoring followed by calling any virtual member function (if present...) would most likely cause an exception. Depending upon the compiler used, accessing data from a restored object may be problematic as well.

The exact semantics of how & where the vtable is located in memory is compiler-dependent, so you would need to look further into your compiler's documentation or play with a debugger to confirm if you are interested.
Reply With Quote