Tuesday, 20 August 2013

open and get exact size of existing memory mapped file on windows

open and get exact size of existing memory mapped file on windows

There is one of our service log file which mapped to memory. I have
another application tracing some regex on log file, so I need to get log
file size periodically and read coming lines if any. I check log file size
by ftell() to get size in bytes however it returns 4mb since it is mapped
to 4mb are I guess. My logic simply like below:
FILE *f = fopen("logfile.log", "r")
fseek(f, previousEnd, SEEK_SET)
// ftell() always returns 4mb when actual file size is less than 4mb
// I need to get exact size of log file
currentEnd = ftell(f)
//read from previousEnd to currentEnd with fread
previousEnd = currentEnd
Is there a way to get exact size of existing mapped files in bytes on
windows? Any suggestion and idea appreciated. Thanks.

No comments:

Post a Comment