I wrote a simple program in c++ that does some calculations, outputs a number to a textfile, and repeats. Several million times. The final text file was around 215 megabytes, yet when I opened it, gedit took over 5 minutes to open all of it, and I went over my 4 Gb of ram and into the linux swap. Why does this happen when the original file size is only 200 MB?

link|improve this question

71% accept rate
2  
gedit is the one using up high amounts of memory, not your own program, right? – Dre Mar 9 '11 at 2:30
Correct. The program when executed took up under 20 Mb but slowly rose by about .1 Mb every minute. – a sandwhich Mar 9 '11 at 2:31
feedback

migrated from stackoverflow.com Mar 9 '11 at 2:44

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 4 down vote accepted

Searching around on Google, gedit seems to handle large files very badly

I would try opening the files in something like less

vim by default does not behave as well as I thought it did on large files, if you want to use vim you should use something like http://www.vim.org/scripts/script.php?script_id=1506

link|improve this answer
Well, I just tried opening the file in gvim, and the ram usage only increased by about 230 MB. It is funny, I opened a program written in c a while ago that was about 100 mb, but gedit didn't react so severly. Thanks. – a sandwhich Mar 9 '11 at 2:42
And to answer the other part of your question, I really do not know why gedit uses that much memory -- may be partly due to bad programming, or a bug. I don't see any reason why it should. If you want the least memory intensive way to view a huge file, I think less is the only way to go, from my digging ( you can't edit it in that case, though ) – Dre Mar 9 '11 at 2:45
+1 for less! I once had to open a 37.1 GiB file and only less worked! – AndrejaKo Mar 9 '11 at 2:52
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.