469,648 Members | 1,153 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

Reading and writing from File

Hi

I am using sun solaris 5.9 operating system.Sometimes after reading from and while writing to file process size used to get increase.(it can be after 20th times 40 th time)
I doesn't happen always but some time.After putting print statements i identified the point.Can any body tell me whether it will going to come in memory leak or normal process usuage.If it comes under memory leak how to slove?I have marked the code below from where it used to get increase.

Appreciate ur input in this.I have tried flushing out o/p buffer.But result is same.

Waiting for any input...............

char mm2_fname [MAXNAMLEN];
char def_fname [MAXNAMLEN];
char temp [MAXNAMLEN];
char file_id [MAXNAMLEN];
char fileTime [MAXNAMLEN];
char latestTime [MAXNAMLEN];
char currentTime [MAXNAMLEN];
char* timeStamp=0;

DIR *dirMMII=0;

if((dirMMII = opendir(MMIIFilePath)) == NULL)
{
return ;
}

struct dirent *mm2_flist=0;
while((mm2_flist = readdir(dirMMII)) != NULL)
{


if(::strstr(mm2_flist->d_name,".") == NULL)
continue;

if(::strstr(mm2_flist->d_name,"pmC") != NULL)
{
char* mmII_token = strrchr(mm2_flist->d_name, '.');
if (mmII_token == 0)
{
continue;
}
int prefixLen = mmII_token - mm2_flist->d_name;
strncpy(file_id, mm2_flist->d_name, prefixLen);
file_id[prefixLen] = '\0';

strcpy(fileTime, mm2_flist->d_name+prefixLen+1);
int prefixLen2 = strlen(fileTime);

char* latestTime_token = fileTime + (prefixLen2-4);
strcpy(latestTime, latestTime_token);

char* currentTime_token = _collectionPeriod + (prefixLen2-4);
strcpy(currentTime, currentTime_token);




if (strcmp(latestTime, currentTime) > 0)
{
timeStamp = fileTime;
}
else
{
timeStamp = _collectionPeriod;
}

if ((strcmp(currentTime, "2330") == 0) && (strcmp(latestTime, "0000") == 0))
{
timeStamp = fileTime;
}


sprintf(mm2_fname,"%s/%s", MMIIFilePath, mm2_flist->d_name);

// build def filename
sprintf(def_fname,"%s/%s.%s", DefaultFilePath,file_id, timeStamp);

// open the file for read
ifstream fin(mm2_fname);
DBG(7,"Open for read file: " << mm2_fname);
if(!fin)
{

return ;
}


ofstream fout(def_fname, ios::app);
DBG(7,"Open for writing file: " << def_fname);
if(!fout)
{

return
}

// append the contents
DBG(7,"Reading from " << mm2_fname << " and writing into " << def_fname);


while( fin >> temp )
fout << temp << endl;<--- This is the point where process size increase
fin.close();
fout.close();
}
}
closedir(dirMMII);
return ;
}
Nov 28 '06 #1
0 1409

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Oliver Knoll | last post: by
2 posts views Thread by John Salerno | last post: by
8 posts views Thread by smeenehan | last post: by
6 posts views Thread by arne.muller | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.