Click here to Skip to main content
15,921,113 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: bitmap Pin
John R. Shaw6-Apr-04 16:48
John R. Shaw6-Apr-04 16:48 
GeneralMenu Pin
Rassul Yunussov6-Apr-04 0:07
Rassul Yunussov6-Apr-04 0:07 
GeneralRe: Menu Pin
Empty19816-Apr-04 0:36
Empty19816-Apr-04 0:36 
GeneralRe: Menu Pin
Antony M Kancidrowski6-Apr-04 1:22
Antony M Kancidrowski6-Apr-04 1:22 
GeneralRe: Menu Pin
Rassul Yunussov6-Apr-04 22:30
Rassul Yunussov6-Apr-04 22:30 
GeneralRe: Menu Pin
Antony M Kancidrowski7-Apr-04 2:12
Antony M Kancidrowski7-Apr-04 2:12 
Generalavenger_sb25//read, write data files Pin
dairiseky5-Apr-04 23:53
dairiseky5-Apr-04 23:53 
GeneralRe: avenger_sb25//read, write data files Pin
Steve S6-Apr-04 1:21
Steve S6-Apr-04 1:21 
Ah. You've been told how to without any understanding of what's happening, which makes it difficult to fix this minor problem.

The line

outfile.write( (char*) objectA, sizeof(objectA));

should probably read

outfile.write( (char*)&objectA, sizeof(objectA));

as you need to specify the address.

Essentially, it's writing everything from memory to do with objectA's storage out to disk. This is not necessarily a good thing.
If objectA contains any pointers, or has other objects embedded within it, you may well be able to read objectA back some time later, but then not be able to use it.

Serialising an object is something that the object itself should know how to do, since it is possibly the only entity aware of all it's members. A blind write (and read) of the space occupied does not take into account the fact that the object may refer to other things, such as a char* member. In that case, the address in the char* member would be written out, and not the string it's pointing to1. When the object is later read back, the same address is assigned. Now if the memory map has changed significantly, it's possible that the address is not only not pointing to the right data, but it may in fact be pointing to unallocated or deallocated memory, which will cause an exception in your app.

Steve S
1Yes, I know it's not a proper string, it's only an illustration, so calm down... Smile | :)
GeneralRe: avenger_sb25//read, write data files Pin
avenger_sb256-Apr-04 11:15
avenger_sb256-Apr-04 11:15 
GeneralRe: avenger_sb25//read, write data files Pin
David Crow6-Apr-04 2:11
David Crow6-Apr-04 2:11 
GeneralRe: why binary? Pin
dairiseky6-Apr-04 2:32
dairiseky6-Apr-04 2:32 
GeneralRe: why binary? Pin
David Crow6-Apr-04 3:27
David Crow6-Apr-04 3:27 
GeneralRe: avenger_sb25//read, write data files Pin
avenger_sb256-Apr-04 11:12
avenger_sb256-Apr-04 11:12 
GeneralRe: avenger_sb25//read, write data files Pin
dairiseky6-Apr-04 23:48
dairiseky6-Apr-04 23:48 
GeneralRe: avenger_sb25//read, write data files Pin
Anonymous7-Apr-04 3:27
Anonymous7-Apr-04 3:27 
GeneralRe: avenger_sb25//read, write data files Pin
avenger_sb257-Apr-04 3:35
avenger_sb257-Apr-04 3:35 
GeneralRe: avenger_sb25//read, write data files Pin
dairiseky7-Apr-04 5:32
dairiseky7-Apr-04 5:32 
GeneralOracle Stored Procedure Problem in .NET Pin
Anonymous5-Apr-04 23:20
Anonymous5-Apr-04 23:20 
QuestionGDI+ question: Bitmap:FromFile, how to detect non-existent image file? Pin
Indrawati5-Apr-04 22:39
Indrawati5-Apr-04 22:39 
AnswerRe: GDI+ question: Bitmap:FromFile, how to detect non-existent image file? Pin
Mike Dimmick5-Apr-04 23:43
Mike Dimmick5-Apr-04 23:43 
AnswerRe: GDI+ question: Bitmap:FromFile, how to detect non-existent image file? Pin
JonCage6-Apr-04 1:37
JonCage6-Apr-04 1:37 
GeneralWindows idle time Pin
Florin Ochiana5-Apr-04 22:28
Florin Ochiana5-Apr-04 22:28 
GeneralRe: Windows idle time Pin
Rage5-Apr-04 22:35
professionalRage5-Apr-04 22:35 
GeneralRe: Windows idle time Pin
Florin Ochiana5-Apr-04 22:43
Florin Ochiana5-Apr-04 22:43 
GeneralRe: Windows idle time Pin
Rage5-Apr-04 22:48
professionalRage5-Apr-04 22:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.