Help -fwrite consuming lot of memory !!!


 
Thread Tools Search this Thread
Top Forums Programming Help -fwrite consuming lot of memory !!!
# 1  
Old 07-19-2005
Error Help -fwrite consuming lot of memory !!!

Hi ,

I am running a C/C++ program on a solaris 5.8 machine. This parituclar application has a module which saves data to a file. The module uses fwrite() function to save data.

The fwrite function write about 500 MB of data to a file. The problem which I am facing is, the memory consumtion of the process increases during the fwrite but does not decrease once the fwrite is over.

I tried fflush(filepointer) after the fwrite but did not help.

The fwrite function writes all the data in once single fwrite() statement. I initially thought the increase in memory was because of this. So I tried writing data in smaller chunks of sizes 100 MB and 50 MB but still the memory utilization of the process does not decreases once the fwrite is over.

As a result a lot of the main memory is being eaten by this process and thus making the system very slow.

Please help me .


Thanks in advance

ajphaj
# 2  
Old 07-19-2005
That's right processes will not shrink when you're using the malloc library even indirectly. Maybe you can fork(). Let the child write the data and then exit.
# 3  
Old 07-19-2005
You can try using the open() system call with O_SYNC flag, then call write() every 1MB of data.

O_SYNC turns off file buffering, in that every call to write waits until the underlying hardware has completed writing the data.

For fwrite(), setvbuf() and setbuf() do somewhat the same thing.

A word of warning: turning off buffering completely is a very bad idea in terms of performance. Especially on writing really big files.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding the most memory consuming processes in Linux

Platform: Oracle Linux 6.4 To find the most memory consuming processes, I tried the following 2 methods 1. Method1 # ps aux | head -1 ; ps aux | sort -nk +4 | tail -7 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 95 0.0 0.0 0 0 ? ... (2 Replies)
Discussion started by: kraljic
2 Replies

2. AIX

Which process was consuming most memory in the Past?

Hello There are options / commands to check which process is consuming maximum memory However is there any command/mechanism which will tell us which process was consuming maximum memory in specific time interval in the past? I heard nmon report can help in this regard. is there any... (5 Replies)
Discussion started by: Chetanz
5 Replies

3. Shell Programming and Scripting

Discrepancy in finding the top memory consuming processes

When I run 'top' command,I see the following Memory: 32G real, 12G free, 96G swap free Though it shows as 12G free,I am not able to account for processes that consume the rest 20G. In my understanding some process should be consuming atleast 15-16 G but I am not able to find them. Is... (1 Reply)
Discussion started by: prasperl
1 Replies

4. Programming

What happens fwrite/fread at the same time?

Hello, I have a question about what happens when I copy the file which is being written by another process on Solaris 9/SPARC, UFS file system. in particular, I want to know what happens while some process is reading the file using fread or mmap, another process try to write something on the... (4 Replies)
Discussion started by: wipe3out
4 Replies

5. Programming

segmentation fault in fwrite function

Hi, my code is written in proC and it is in UNIX(AIX).I have written a small code for writing data into a binary file,but while writing my program is giving core dump. Here Is my code---- fpWriteFile = fopen(WriteFileName,"wb+"); CHAR *recvgen; recvgen = (char... (7 Replies)
Discussion started by: ajaysahoo
7 Replies

6. AIX

Command to find TOP 5 Memory consuming process

HI All, Can anyone send me a command to find TOP 5 Memory consuming process. It would be lelpful if I get output something like below processname - pid - memory(in MB) - command I tried few commands from the internet but the result only give the real memory usage or pagging, I want total... (4 Replies)
Discussion started by: bce_groups
4 Replies

7. AIX

Process consuming most memory

How can i find the processes that is consuming most memory? I tried TOPAS and SVMON and this didn't gave me the desired result. (1 Reply)
Discussion started by: shabu
1 Replies

8. Programming

fwrite in Linux and UNIX

Hi I have an fwrite function in my C++ application. It is able to create the files in HP-UX. cross is one structure rec2 is another structure within cross. fwrite_return = fwrite( &cross.rec2, sizeof(cross.rec2), ... (14 Replies)
Discussion started by: rkraj
14 Replies

9. Programming

How system deamons consuming less memory

Dear all, When I write the daemon programs it is consuming high memory and processor time. How can I avoid this? But, the system daemons are not consuming more. How? Can any one explain how the system daemons are handling the memory consumption and processor time. Thanks,... (1 Reply)
Discussion started by: nagalenoj
1 Replies

10. Programming

fwrite throws segmentation fault

Code : function sSaveTFFile ....................... iRetCode = link (caCurrentFilename, caBackupFilename); if (iRetCode == -1) { ERR_MSG2(LOG_ALERT, "Can't move %s to %s", caCurrentFilename, caBackupFilename); return(FAILURE); } iRetCode = unlink... (6 Replies)
Discussion started by: fermisoft
6 Replies
Login or Register to Ask a Question