a question about using printlog function

Archive of the old Parsimony forum. Some messages couldn't be restored. Limitations: Search for authors does not work, Parsimony specific formats do not work, threaded view does not work properly. Posting is disabled.

a question about using printlog function

Postby Uri Blass » 01 Mar 2004, 21:03

Geschrieben von: / Posted by: Uri Blass at 01 March 2004 21:03:45:

I decided to use the PrintLog function and I have a question about using it
Today I print the hash size both on the screen and on the logfile by
logmovei=fopen(logstring, "a+t");
fseek(logmovei,0,SEEK_END);
fprintf(logmovei,"hash in mbytes=%d\n",hash_in_mbytes);
fclose(logmovei);
printf(" hash size in mbytes ");
printf(" %d ",hash_in_mbytes);

The question is what exactly I should delete from that code
It is clear to me that I should add
PrintLog("hash in mbytes=%d\n",hash_in_mbytes);
I see that I can do my code slightly smaller by deleting
fprintf(logmovei,"hash in mbytes=%d\n",hash_in_mbytes);
printf(" hash size in mbytes ");
printf(" %d ",hash_in_mbytes);
There is a difference when it print new line on the screen but the difference is not important
I guess that I can delete also the fseek command.
The point is that I believe that having always fopen fclose is not efficient programming.
I thought that it may be better to have one fopen and one fclose when I go out of the program but I do not want the program to forget to close files because of a bug so I think that fopen and fclose should be in the original PrintLog function and I wonder if there is a reason that it is not there.

Here is again the PrintLog function.
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}



Uri
Uri Blass
 

Re: a question about using printlog function

Postby Tom Likens » 02 Mar 2004, 00:25

Geschrieben von: / Posted by: Tom Likens at 02 March 2004 00:25:30:
Als Antwort auf: / In reply to: a question about using printlog function geschrieben von: / posted by: Uri Blass at 01 March 2004 21:03:45:
The point is that I believe that having always fopen fclose is not efficient
programming. I thought that it may be better to have one fopen and one fclose
when I go out of the program but I do not want the program to forget to close
files because of a bug so I think that fopen and fclose should be in the
original PrintLog function and I wonder if there is a reason that it is not
there.
Hey Uri,
I'd be hesitant to open and close the log file everytime you wanted
to write to it. If you only write to it occasionally it might be okay,
but I find that almost everywhere I previously used a regular printf
statement I now instead use the "print" statement (my equivalent "PrintLog"
routine). I believe (without evidence to back it up at the moment) that
opening and closing the log file each time would be a huge performance hit
for my program.
YMMV, but I'd profile it both ways before I made a decision.
regards,
--tom
Tom Likens
 

Re: a question about using printlog function

Postby Federico Corigliano » 02 Mar 2004, 00:32

Geschrieben von: / Posted by: Federico Corigliano at 02 March 2004 00:32:00:
Als Antwort auf: / In reply to: a question about using printlog function geschrieben von: / posted by: Uri Blass at 01 March 2004 21:03:45:

When I created a Trace tool for my engines (that now was deleted), I opened and closed the trace file each time that something is wrote. That resulted in too much disk access and a big performance decrease.
A recommendation for you is to create 2 functions. One InitLog(), that should be called when the engine starts, and one ShutDownEngine(int returnCode) that should be called instead of exit(). In this function you can close all the open files and close other things that need a clean (such as dynamic memory).
Federico
I decided to use the PrintLog function and I have a question about using it
Today I print the hash size both on the screen and on the logfile by
logmovei=fopen(logstring, "a+t");
fseek(logmovei,0,SEEK_END);
fprintf(logmovei,"hash in mbytes=%d\n",hash_in_mbytes);
fclose(logmovei);
printf(" hash size in mbytes ");
printf(" %d ",hash_in_mbytes);

The question is what exactly I should delete from that code
It is clear to me that I should add
PrintLog("hash in mbytes=%d\n",hash_in_mbytes);
I see that I can do my code slightly smaller by deleting
fprintf(logmovei,"hash in mbytes=%d\n",hash_in_mbytes);
printf(" hash size in mbytes ");
printf(" %d ",hash_in_mbytes);
There is a difference when it print new line on the screen but the difference is not important
I guess that I can delete also the fseek command.
The point is that I believe that having always fopen fclose is not efficient programming.
I thought that it may be better to have one fopen and one fclose when I go out of the program but I do not want the program to forget to close files because of a bug so I think that fopen and fclose should be in the original PrintLog function and I wonder if there is a reason that it is not there.

Here is again the PrintLog function.
void __cdecl PrintLog(const char *szFormat, ...)
{
va_list vargs;
va_start(vargs, szFormat);
vprintf(szFormat, vargs);
fflush(stdout);
if (g_bLogging && logmovei != (FILE *)NULL)
{
vfprintf(logmovei, szFormat, vargs);
fflush(logmovei);
}
va_end(vargs);
}


Uri
Federico Corigliano
 

Re: a question about using printlog function

Postby Uri Blass » 02 Mar 2004, 01:17

Geschrieben von: / Posted by: Uri Blass at 02 March 2004 01:17:00:
Als Antwort auf: / In reply to: Re: a question about using printlog function geschrieben von: / posted by: Tom Likens at 02 March 2004 00:25:30:
The point is that I believe that having always fopen fclose is not efficient
programming. I thought that it may be better to have one fopen and one fclose
when I go out of the program but I do not want the program to forget to close
files because of a bug so I think that fopen and fclose should be in the
original PrintLog function and I wonder if there is a reason that it is not
there.
Hey Uri,
I'd be hesitant to open and close the log file everytime you wanted
to write to it. If you only write to it occasionally it might be okay,
but I find that almost everywhere I previously used a regular printf
statement I now instead use the "print" statement (my equivalent "PrintLog"
routine). I believe (without evidence to back it up at the moment) that
opening and closing the log file each time would be a huge performance hit
for my program.
YMMV, but I'd profile it both ways before I made a decision.
regards,
--tom
I understand.
Today I do not write to the logfile during search but only at the end of the search.
I think that if the program writes a lot to the logfile then it is probably better to have log off as the default option and the problem of speed is not a real problem because it never happens in tournaments.
If you do not use log off as the default option then your program may generate a logfile of some mbytes every game and the logfile may be so big that practically the user will have often to delete logfiles from his computer in order to continue to use the program.
Today movei does not use big logfiles and only use the same name for logfile but I think that it is not nice to the user that there is no option of log off and maybe I will release an update for movei when log is off unless the user take active action for activating log.
After all I think that people may blame me of generating a virus because the logfile takes more and more of the computer memory if they do not delete it.
I know that there are other programs who behave the same like yace but I think that it is possible that both me and Dieter are wrong by generating application that its default property is to steal memory from the computer of the user.
After all computers have limited memory and the computer may crush if the logfile steal too much memory and even if it steal only 1 kbyte of memory this 1 kbyte may be 1 kbyte too much when you add it to the memory that other applications steal.
I think that it is more fair to have default property of not stealing memory and to steal memory only if the user changes the number of stealing memory from 0 to 1.
Uri
Uri Blass
 


Return to Archive (Old Parsimony Forum)

Who is online

Users browsing this forum: No registered users and 39 guests