C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 20th, 2005, 08:51 AM
onebug onebug is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 8 onebug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m 26 sec
Reputation Power: 0
writing file, memory not released

i use redhat linux, gcc compiler. in my code, i write out data at certain time interval with different file names, and i use fopen and fclose after each write-out. but when i check the memory usage, it keeps increasing after each call to output the data. ??? any help is appreciated... thanks.

Reply With Quote
  #2  
Old June 20th, 2005, 08:53 AM
naddad naddad is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 235 naddad User rank is Private First Class (20 - 50 Reputation Level)naddad User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 3 Days 14 h 27 m 20 sec
Reputation Power: 9
show code. Are u allocating memory dynamically?

Reply With Quote
  #3  
Old June 20th, 2005, 10:06 AM
onebug onebug is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 8 onebug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m 26 sec
Reputation Power: 0
writing file, memory not released

at the beginning, i allocate variable q dynamically. and q is kept throughout the running process (no free and re-allocate is done). basically the code:

PHP Code:
 main()
{
    
allocate q[isize][jsize
    
time loop
        
do something with the data
        
if plot_time is reached 
             plotdata
()  //write out q
    
end time loop
}

void plotdata()
{
    
FILE*fplot
    fplot 
fopen(filename,"w"//filename is different for different time

    
writeout data

    fclose
(fplot)


Reply With Quote
  #4  
Old June 20th, 2005, 10:11 AM
naddad naddad is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 235 naddad User rank is Private First Class (20 - 50 Reputation Level)naddad User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 3 Days 14 h 27 m 20 sec
Reputation Power: 9
This pseudo-code does not help at all... what does plotdata do? allocating by q[n][p] is NOT called dynamic allocation. Dynamic allocation uses malloc() or new...
Comments on this post
E D D ! 3 agrees!

Reply With Quote
  #5  
Old June 20th, 2005, 12:35 PM
onebug onebug is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 8 onebug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m 26 sec
Reputation Power: 0
oh...i just put allocate q[n][m]... but in fact, i use malloc to allocate memory for q and this is done correctly, i've checked.

in plotdata()... just writing out q to a data file using
fprintf(fplot,"...."); and nothing else. then the file is closed after it's done.

could this have something to do with the compiler?

Reply With Quote
  #6  
Old June 20th, 2005, 12:57 PM
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2004
Posts: 1,676 Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level)Dave Sinkula User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 8 h 23 m 46 sec
Reputation Power: 132
Quote:
Originally Posted by onebug
could this have something to do with the compiler?
Generally not. I'd post your actual code first.
__________________
Any advertisement triggered by IntelliTxt in this post is not endorsed by the author of this post.

Reply With Quote
  #7  
Old June 20th, 2005, 01:46 PM
onebug onebug is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 8 onebug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m 26 sec
Reputation Power: 0
i cut out some unnecessary details (ex: initializing some vars, etc.). okay here goes:

PHP Code:
 int main(void)
{
  
int    iter;
  
double tcount;

  
iter 0;
  
mem_alloc();

  while (
time_current time_end) {
    
iter++;
    
time_current += dtmin;
    
tcount += dtmin;
    if (
tcount >= tplot) {
      
tcount tcount tplot;
      
plotdata(iter);
    }
  } 
  
  return 
0;



PHP Code:
 void plotdata(const int iter)
{
  
short  i,j;
  
FILE   *fplot;
  
char   filename[20];

  
sprintf(filename,"data/%05d.dat",iter);
  
fplot fopen(filename,"w");

  for (
0NYMAXj++)
    for(
0NXMAXi++) {       
      
fprintf(fplot,"%15.10e %15.10 %10.3e \n",x[i],y[j],q[i][j][0]);
    } 
  
  
fclose(fplot);  




PHP Code:
 void mem_alloc()
{
  
short i,j,nvars;
  
nvars 2;

  
= (double ***) malloc(NXMAX*sizeof(double **));

  for (
0NXMAXi++) {
     
q[i] = (double **) malloc(NYMAX*sizeof(double *));
     for (
0NYMAXj++) {
       
q[i][j] = (double *) malloc(nvars*sizeof(double));
     }
  }


Reply With Quote
  #8  
Old June 20th, 2005, 02:04 PM
naddad naddad is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 235 naddad User rank is Private First Class (20 - 50 Reputation Level)naddad User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 3 Days 14 h 27 m 20 sec
Reputation Power: 9
I honestly don't see any memory leaks except in ur mem_alloc() function which is called only once. Perhaps they're in the "unnecessary details"....

Reply With Quote
  #9  
Old June 21st, 2005, 06:57 AM
onebug onebug is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 8 onebug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m 26 sec
Reputation Power: 0
thanks anyway.
i am almost 100% sure it's not in the "unnecessary details". anyone else has any suggestion?

Reply With Quote
  #10  
Old June 21st, 2005, 07:03 AM
kicken's Avatar
kicken kicken is offline
Wiser? Not exactly.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2001
Location: Bonita Springs, FL
Posts: 5,654 kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)  Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 2 Months 2 Weeks 2 Days 5 h 1 m 44 sec
Reputation Power: 3436
How much does the memory increase by? Does the amount of increase match up w/ any amount of data that you know might be written/created by the program?
__________________
Recycle your old CD's, don't just trash them


Spidermonkey Tutorial;

If I helped out out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

Reply With Quote
  #11  
Old June 21st, 2005, 11:16 AM
onebug onebug is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 8 onebug User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m 26 sec
Reputation Power: 0
i don't have to code in front of me to find out exactly. but from memory, it seems to increase by about 100MB and i think this is related to the size of variables being written out (q). (i make a quick calculation and it's about the same order of magnitude)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > writing file, memory not released

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap