LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-18-2009, 11:35 PM   #1
doug23
LQ Newbie
 
Registered: Aug 2009
Posts: 18

Rep: Reputation: 0
Exclamation Perl File Handler - will autoflush clear the memory the file requires?


Hi All,

Does $filehandle->autoflush(1) force Perl to clear the memory required by the $filehandle?

I understand that it flushed the buffer to the file after every write/print, but if I only need to append lines to a file, and never read the file, will this also reduce the memory requirements of my script?

I am using $filehandle along with Text::CSV_XS.

I will be reading in a >100GB file, and storing a large buffer of 20GB in filehandles waiting to write would significantly bog down (if not crash) the application.

Also, is there any difference in memory requirements between opening the filehandler's file in ">" mode versus append ">>" mode?

Are these the only two additions I would need to make to the code, or would I need to create a new IO object first?

Code:
use IO::Handle; 

	# create new output file for that year
	my $curOUTERRORfile = "ERRORSyear$CURyear.csv";

	my $curOUTERRORfilecsv = Text::CSV_XS-> new ({ binary => 1, eol => $/ });
	open my $curOUTERRORfilefh, ">", "$curOUTERRORfile" or die "$curOUTERRORfile: $!";
	$curOUTERRORfilefh->autoflush(1); 

Thanks for your help!!!

Doug

Last edited by doug23; 08-19-2009 at 12:12 AM. Reason: added a question
 
Old 08-19-2009, 01:39 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
autoflush only flushes the output buffer ie any/all 'data' previously 'written out' by a print cmd (or equiv).
It has nothing to do with any data you have in memory. Once you've issued a print cmd, that data is written to a mem buffer, and then to the disk if decided by the OS. If you have autoflush on, it writes it to disk immediately, instead of buffering. I'm pretty sure the buffer mem is still attached, just empty.
Think of it as write-through buffering.
http://perldoc.perl.org/IO/Handle.html
 
Old 08-19-2009, 08:57 AM   #3
doug23
LQ Newbie
 
Registered: Aug 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
autoflush only flushes the output buffer ie any/all 'data' previously 'written out' by a print cmd (or equiv).
It has nothing to do with any data you have in memory. Once you've issued a print cmd, that data is written to a mem buffer, and then to the disk if decided by the OS. If you have autoflush on, it writes it to disk immediately, instead of buffering. I'm pretty sure the buffer mem is still attached, just empty.
Think of it as write-through buffering.
http://perldoc.perl.org/IO/Handle.html

Thanks. I have looked through the site before.

Right, so in terms of stuff I print (say 20-50gb) to that filehandle, will the code as it is written now no longer store the full 20-50gb in stuff I printed to the file in the buffer?
 
Old 08-20-2009, 12:32 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
The buffer is a small fixed amt of mem, the OS doesn't try to buffer the whole lot in mem. Without autoflush, it fills the buffer and then writes to disk when the buffer fills up. With autoflush, it writes through the buffer to disk immediately.
Here's a really good page about it http://perl.plover.com/FAQs/Buffering.html
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl file handler in recursive function enemorales Programming 4 02-02-2009 03:20 PM
How to modify a field in few lines in a file and save the new file - in Perl rounak94 Programming 1 10-02-2008 07:43 PM
Perl file conversion results in a truncated file kshaffer Programming 0 01-31-2005 02:31 PM
File Handler Limitations in Linux? m3kgt Linux - General 2 01-09-2004 01:08 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration