473,385 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1631

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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.