Home | Reviews | GUIpedia | Forum | Fun500

DickLoading Files
In applications such as text and image editors, the content to be processed will have to be loaded to memory. In 16 bit dos, there is often very little memory available. In an app like a text editor, if the file is say 5 mb, how would you recommend it be loaded? In pages/chunks, or to be directly modified with file i/o. What do you think would be the best way to load it in pages or chunks?
2011-11-138:12 PM

pharoahRe:Loading Files
I'd recommend loading the file into memory in chunks. You'll want to have a swap file in some convenient format (perhaps a random access file). That way, you can save back intermediate changes to parts of the file as the user moves between chunks without forcing them to write over their original file.
2011-11-138:23 PM

Or you could make an entire temporary copy of the file and only use file IO, save memory, but it would be slower. I wonder how MS notepad does this, if I remember correctly, it just fails to open files too large, or takes a very long time to load larger files which perhaps means it loads the entire thing onto RAM.
2011-11-1411:29 AM

pharoahRe:Loading Files
If you only use file IO, and the user inserts something in the middle of the file, you have to rewrite from there all the way to the end of the file. That's why it might be better to have a temp file that stores everything in chunks with some extra space (perhaps chr$(0)s) at the end. That way you don't have to shift things around if someone makes a minor edit, only if they add a paragraph. Each chunk could be used to store one line in the source file, for example, and it could be a 255 or 512 zero-padded record (don't pad it with spaces, maybe the user wants to have a space at the end of the line). There would be a few more details to work out with this, but I still advise it as the best course of action for editing large files, and you could cache some things in memory easily for greater speed.
2011-11-143:51 PM

BASIC Programming Help

2021 Brandon Cornell

Fatal error: Uncaught Error: Call to a member function close() on null in /homepages/11/d157582457/htdocs/mblog/footer.php:20 Stack trace: #0 /homepages/11/d157582457/htdocs/mblog/forum.php(88): include() #1 {main} thrown in /homepages/11/d157582457/htdocs/mblog/footer.php on line 20