473,614 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading and writing from File

26 New Member
Hi

I am using sun solaris 5.9 operating system.Sometime s 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(MMIIFil ePath)) == NULL)
{
return ;
}

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


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

if(::strstr(mm2 _flist->d_name,"pmC" ) != NULL)
{
char* mmII_token = strrchr(mm2_fli st->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+prefixL en+1);
int prefixLen2 = strlen(fileTime );

char* latestTime_toke n = fileTime + (prefixLen2-4);
strcpy(latestTi me, latestTime_toke n);

char* currentTime_tok en = _collectionPeri od + (prefixLen2-4);
strcpy(currentT ime, currentTime_tok en);




if (strcmp(latestT ime, currentTime) > 0)
{
timeStamp = fileTime;
}
else
{
timeStamp = _collectionPeri od;
}

if ((strcmp(curren tTime, "2330") == 0) && (strcmp(latestT ime, "0000") == 0))
{
timeStamp = fileTime;
}


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

// build def filename
sprintf(def_fna me,"%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(dirMMI I);
return ;
}
Nov 28 '06 #1
0 1646

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

Similar topics

4
9821
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 = tmpfile(); /* write into tmpFile */ ...
2
3061
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 array). I cannot change anything in the program but can add some features by which I can convert this array of data into a file. The easiest thing would be to write the data into a file (in hard disk) and use it. But I will be working on thousands...
2
2007
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 contents. System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\positions.txt"); System.IO.StringReader myFile = new System.IO.StringReader(@"C:\positions.txt"); for (int i = 0; i < 3; i++)
7
6097
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 --------/--------/--------/--------/--------/--------/ // field_width=8 For example, I position my file pointer at the begining of the 4th fileld lets say 25th character(3*(field_width)+1) and when I try to
8
2663
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 different image files shuffled up in one big binary file. In order to view them I have to "unshuffle" the data, which means moving bytes around. Currently my approach is to read the data from the original, unshuffle as necessary, and then write...
5
5065
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 have it store info it gets from when the programs check in into a DataSet (XML file). Problem is, that file now has to be used by other programs to find out version information (the file is ALWAYS less that 1K.) The record itself is only five fields...
6
5258
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
1077
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 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...
42
4843
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 if I am wrong. If possible could anybody help me with sample code for reading and writing a simple text file.I have seen there are many ways to read /write the data in Python.But I want to use the effective way of reading or writing the data...
0
8620
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8571
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8265
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5537
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4048
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4115
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2560
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1705
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.