472,953 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,953 software developers and data experts.

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 1609

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

Similar topics

4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
2
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is written to work on data from a file (not from an...
2
by: John Salerno | last post by:
I wrote this code just to experiment with writing to and reading from a file. It seems to work fine when writing, but when reading the file, it only prints the filepath to the screen, not the file...
7
by: utab | last post by:
Hi there, I am trying to read from a file and at the same time change certain fields of the same field, there are 6 fields in this file like 1 2 3 4 5 6...
8
by: smeenehan | last post by:
This is a bit of a peculiar problem. First off, this relates to Python Challenge #12, so if you are attempting those and have yet to finish #12, as there are potential spoilers here. I have five...
5
by: UJ | last post by:
I have a system that has five programs that all communicate with each other via Message Queues. Works well. One program is a watchdog that will make sure the others are up and going. Currently I...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
0
by: yogesh_anand | last post by:
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...
42
by: psbasha | last post by:
Hi, Is it necessary in Python to close the File after reading or writing the data to file?.While refering to Python material ,I saw some where mentioning that no need to close the file.Correct me...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.