About DEBUG interrupt, memory problems! ! !

Category: C/C++ -> C++ Author: liaopengaiwangli1111 Date: 2007-05-16 10:09:27
 
liaopengaiwangli1111
2007-05-16 10:09:27
Procedure is as follows:
front omitted. . . . . .
xtfdata is a structure.
CFile file0;
file0.Open (emfilename, CFile :: modeWrite | CFile :: modeCreate | CFile :: modeNoTruncate);
buchang4 = 4;
buchang1 = 1;
buchang2 = 2;
buchang8 = 8;
CString str;
double pai = 3.14159265358979323846;
file.Open (filename, CFile :: modeRead );
tlength = file.GetLength ();
file.Seek (0, CFile :: begin);
file.Read (& data1, buchang1);
memcpy (& xtfdata.FileFormat, & data1, buchang1);
CString test;

test.Format ("% d", xtfdata.FileFormat);

texttest = CString ("XTFFileHEADER") + CString ("\ r \ n") + CString ("FileFormat:") + test + CString ("\ r \ n");
file0.Write ((LPCTSTR) texttest, texttest.GetLength () +1);
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
file.Seek (10, CFile :: begin);
file.Read (& data8, buchang8 );
memcpy (& xtfdata.RecordingProgramVersion, & data8, buchang8);
test.Format ("% s", xtfdata.RecordingProgramVersion);

texttest = CString ("RecordingProgramVersion [8]:") + test + CString ("\ r \ n");
file0.Write ((LPCTSTR) texttest, texttest.GetLength () +1);
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / WORD SonarType
file.Seek (34, CFile :: begin);
file.Read (& data2, buchang2);
memcpy (& xtfdata.SonarType, & data2, buchang2);
test.Format ("% u", xtfdata.SonarType) ;
texttest = CString ("SonarType:") + test + CString ("\ r \ n");
file0.Write ((LPCTSTR) texttest, texttest.GetLength () +1 );
/ / / / / / / / / / / / / / / / / / / / / / / / / / long NavigationLatency
file.Seek (204, CFile :: begin) ;
file.Read (& data4, buchang4);
memcpy (& xtfdata.NavigationLatency, & data4, buchang4);
test.Format ("% lu", xtfdata . NavigationLatency);
texttest = CString ("NavigationLatency:") + test + CString ("\ r \ n");
file0.Write ((LPCTSTR) texttest, texttest.GetLength ( ) +1);
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
so used repeatedly, or thousands of times (that is to read a format structure, in accordance with the byte read), found that after reading a certain stage DEBUG interrupted, still do not know what is wrong, a few days ago still operating normally, a few days did not change the program, break does not appear for a few days and then open the run, something will appear out of memory, hope heroes!
huohuo3314
2007-05-16 10:24:00
all the variables are initialized to {0}, char xtfdata.RecordingProgramVersion [9]; one more.

xhx711638
2007-05-16 10:34:09
whether a memory leak it?

use Task Manager program occupies memory facie case, if the memory usage has been growing in the code will have to see whether there is not freed resources.
a286890529
2007-05-16 10:43:38
crash when the dialog box by pressing the corresponding button to enter the debugger, press Alt +7 key to view the Call Stack listed from top to bottom inside the correspondence from the inner layer to the outer function call history. Double-click a row to position the cursor to the call at the source code or assembly instructions.

resource leak check whether one of the ways:
process in Task Manager View Select Columns inside options: memory usage, virtual memory size, number of handles, the number of threads, USER objects, GDI objects
your program (process) does not exit, the main process loop executes many times as possible, such as one million times or infinite loop, record the above values, then at least one compartment hours, the longer the better, such as a month, and then record the above values. If the difference between the two sets of values ​​greater than or increasing over time, it would definitely have a corresponding resource resource leaks!
z24977231xxcxgm
2007-05-16 10:52:26
when debugging your debugger can not give abnormal position and function stack it? Look at this location should be easy to find ah.
If the debugger to run dead, print output to a file and then run the narrow range of small-scale errors continue to debug the program, the process is repeated until the debugger still work give the wrong position.
xiaoluaimei1314
2007-05-16 11:09:01
Public xtfdata type of data to look at, maybe in xtfdata.RecordingProgramVersion generate data overflow.
loooo32
2007-05-16 11:27:51
char xtfdata.RecordingProgramVersion [8];

there
BYTE xtfdata.Reserved [53]; I use the same format to convert
BYTE data53 [53];
int buchang53 = 53;
file.Seek (100, CFile :: begin);
file.Read (& data53, buchang53);
memcpy (& xtfdata.Reserved, & data53, buchang53);
test.Format ("% s", xtfdata.Reserved);

texttest = CString (" ; Reserved [53]: ") + test + CString (" \ r \ n ");
file0.Write ((LPCTSTR) texttest, texttest.GetLength () +1);
is said, I turn BYTE array to CString CString and char array to use the same method, so you can do?
clowndirty
2007-05-16 11:47:28
Thank brikehuang! ! ! This is the reason!