Click here to Skip to main content
15,905,967 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Help!! CHTMLView inside CDialog Pin
crewchill24-Jun-03 21:21
crewchill24-Jun-03 21:21 
GeneralLots'o'data... Pin
el davo24-Jun-03 13:25
el davo24-Jun-03 13:25 
GeneralRe: Lots'o'data... Pin
Dave Bryant24-Jun-03 14:34
Dave Bryant24-Jun-03 14:34 
QuestionWhat's wrong with this code? Pin
Jonathan Gilligan24-Jun-03 12:38
Jonathan Gilligan24-Jun-03 12:38 
AnswerRe: What's wrong with this code? Pin
Dave Bryant24-Jun-03 12:43
Dave Bryant24-Jun-03 12:43 
AnswerRe: What's wrong with this code? Pin
ZoogieZork24-Jun-03 14:11
ZoogieZork24-Jun-03 14:11 
GeneralRe: What's wrong with this code? Pin
Jonathan Gilligan25-Jun-03 5:20
Jonathan Gilligan25-Jun-03 5:20 
Generalfopen Pin
cnd1200124-Jun-03 11:11
cnd1200124-Jun-03 11:11 
Hello everybody,

Here is my problem.

I wrote a program that does a statistical analysis, allocating large quantities of memories (3-400 MB) dynamically, and then performs cycles of calculations on the data.
At the end of each cycle, the program opens 2 files in sequence and writes the results to the disk.

With the first file there is no problem, with the second everything goes well for 20-30 cycles (on average, but the figure varies), when the fopen() that should open the file fails, returning a null pointer. If I try to make it open the same file (which is always the same file that it opened without problems for the first 20-30 cycles) passing to the fopen the name in “” instead of passing a variable, it still doesn’t open it.
If I give it a wayout letting it open another file somewhere else, it succeeds and goes on.
At the next cycle, it reopens the old file without problems.
It is as the write permission on that file were temporarily altered in a cycle, to be brought back to their original values in the next cycle.

The problem occurs with 3 different compilers (borland, Visual C++, mingw) and on 2 operating systems (windows NT e windows ME) , running on 2 different machines (both pentium)

I tried to launch the program from the Visual C++ debugger with all the cheks activated, putting also checks on the heap (functions _CrtMemCheckpoint, _ASSERTE( _CrtCheckMemory( ) )), but apparently there is no memory corruption problem.

Here is the function savememory where the error occurs.

//------------------------------------------------------------------------------
// FNCT: Sieve::savememo
//------------------------------------------------------------------------------
void Sieve::savememo(void)
{
int    lr,nd,i,j,b,var1,* fp2;
Node * ndp;

fp = fopen(MEMORYFILE,"w");

fprintf(fp,"\n%d",cyc);
for (lr=1; lr<LAYERS; lr++) {
   fprintf(fp,"\n\nLR %d",lr);
   for (nd=0; nd<nn[lr]->dimlr; nd++) {
      ndp = nn[lr]->nodes[nd];
      fprintf(fp,"\n%3d) ; %.3f ;",nd,ndp->score);
      for (i=0; i<MAXIPNDS; i++) {
         fprintf(fp," [%3d",  ndp->memo.inar[i].ndnr);
         fprintf(fp," %5.2f", ndp->memo.inar[i].wht);
         fprintf(fp," (%3d",  ndp->memo.inar[i].spc.x1);
         fprintf(fp," %3d)",  ndp->memo.inar[i].spc.x2);
         var1 = (int)ndp->memo.inar[i].spon;
         fprintf(fp," %d] ;", var1);
      }
      fprintf(fp," [%5.2f  -1] ;", ndp->memo.bias);
      fprintf(fp," (%2d %2d)",     ndp->memo.a.x1,ndp->memo.a.x2);
      fprintf(fp," (%2d %2d)",     ndp->memo.b.x1,ndp->memo.b.x2);
   }
}

if (fclose(fp)) 
   printf("Error closing file\n");

#ifdef DEBUG2
printf("AFTER WRITE MEMORYFILE I AM! \n");
printf("\n%s %d\n", DNAMEMFILE, cyc);
#endif
fp = fopen(DNAMEMFILE,"w");
#ifdef DEBUG2
printf("\nfp: %p\n", fp);
//fprintf(fp,"\n%d",cyc);
if (fp == NULL) 
   fp = fopen("C:\\ZEUG\\ZOS\\MPXVC\\IOX\\MPXDNA0.TXT","w");  
if (fp == NULL) fp = fopen("C:\\ZEUG\\ZOS\\MPXVC\\IOX\\MPXDNA2.TXT","w");  
if (fp == NULL) fp = fopen("C:\\ZEUG\\ZOS\\MPX\\IOX\\MPXDNA3.TXT","w");  
if (fp == NULL) fp = fopen("C:\\ZEUG\\ZOS\\FILE01.txt","wt");  

printf("AFTER fopen(DNAMEMFILE) I AM! \n");
#endif

for (lr=1; lr<LAYERS; lr++)
   for (nd=0; nd<nn[lr]->dimlr; nd++) {
      fprintf(fp,"\n\nlr %d nd %d dimpop %d\n",lr,nd,
         nn[lr]->nodes[nd]->popp->dimpop);
      for (j=0; j<DIMPOP; j++) {
         fprintf(fp,"\n%5.3f %5.3f",nn[lr]->nodes[nd]->popp->guys[j].score,
            nn[lr]->nodes[nd]->popp->guys[j].dd);
         for (b=0; b<DIMDNA; b++) {
            var1 = (int)nn[lr]->nodes[nd]->popp->guys[j].dna[b];
            fprintf(fp," %d",var1);
         }
      }
   }

fclose(fp);
#ifdef DEBUG2
printf("AFTER WRITE DNAMEMFILE I AM! \n");
#endif

}



Help, I’m getting crazy!

Thank you

Alex
GeneralRe: fopen Pin
Neville Franks24-Jun-03 11:44
Neville Franks24-Jun-03 11:44 
GeneralRe: fopen Pin
cnd1200125-Jun-03 22:08
cnd1200125-Jun-03 22:08 
GeneralOld School Help Needed Pin
juglugs24-Jun-03 10:44
juglugs24-Jun-03 10:44 
GeneralRe: Old School Help Needed Pin
John R. Shaw24-Jun-03 11:11
John R. Shaw24-Jun-03 11:11 
GeneralRe: Old School Help Needed Pin
juglugs25-Jun-03 6:39
juglugs25-Jun-03 6:39 
GeneralRe: Old School Help Needed Pin
basementman24-Jun-03 11:12
basementman24-Jun-03 11:12 
GeneralPlotting wave files Pin
Juan Carlos Cobas24-Jun-03 10:36
Juan Carlos Cobas24-Jun-03 10:36 
GeneralCRichEditCtrl and Select All Functionality Pin
ScottPrusinoski24-Jun-03 10:05
ScottPrusinoski24-Jun-03 10:05 
Generalerror with creating a pointer to a struct Pin
johnstonsk24-Jun-03 9:53
johnstonsk24-Jun-03 9:53 
GeneralRe: error with creating a pointer to a struct Pin
Michael Dunn24-Jun-03 10:56
sitebuilderMichael Dunn24-Jun-03 10:56 
GeneralRe: error with creating a pointer to a struct Pin
basementman24-Jun-03 11:16
basementman24-Jun-03 11:16 
GeneralRe: error with creating a pointer to a struct Pin
John R. Shaw24-Jun-03 11:38
John R. Shaw24-Jun-03 11:38 
GeneralResource Editor Pin
butterbean73024-Jun-03 9:20
butterbean73024-Jun-03 9:20 
GeneralI don't inderstand these errors Pin
johnstonsk24-Jun-03 9:06
johnstonsk24-Jun-03 9:06 
GeneralRe: I don't inderstand these errors Pin
peterchen24-Jun-03 9:29
peterchen24-Jun-03 9:29 
GeneralRe: I don't inderstand these errors Pin
johnstonsk24-Jun-03 9:31
johnstonsk24-Jun-03 9:31 
GeneralRe: I don't inderstand these errors Pin
Anonymous24-Jun-03 9:52
Anonymous24-Jun-03 9:52 

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.