views:

190

answers:

4

I want to use a algorithm to reduce memory used to save the particular text file.I don't really know how text is stored but i have an idea in mind.

Would it be better to extend a open source text editor (if yes than which one) or write a text editor myself.

It would be nice if someone could also give me a link or tutorial to some basics on how text editors work and the way data is stored.

Edited to add

To clarify, what I wanted to do is instead of saving duplicates of a word make a hash table and store the address where it needs to be placed.

That way I wouldn't be storing the duplicates.

This would have become specific to a particular text editor.

+3  A: 

Text is basically stored as-is. i.e., every character takes up a byte or two (wide chars), and there is no conversion done on it when it's saved. It might add an end-of-file character or something though. Don't try coming up with your own algorithm to compress these files. That's why zip-files and other archives were created. They're really good at compressing text. If you wanted to add these feature to your text-editor, you'd have to add some sort of post-save hook to zip it, and then put a hook on the open command to unzip it. Unless you wanted to do it by hand every time. Don't try writing the text editor yourself from scratch, unless (maybe) you're writing notepad. Text editors with syntax highlighting aren't very easy to make, even with the proper libraries. I'd say write a plugin for something like Visual Studio or what have you. Or find an open-source text editor.

Mark
I agree with Mark; you could add a gzip function to vim rather easily. Unless you're dealing with text on a monumental scale, though, your space savings are unlikely to be substantial, and you lose the portability of a straight text file. If you use gzip, at least others could open it with some effort, but if you implement this algorithm of yours, nobody could open the file except users of your editor.
Jay
I think `vim` already supports supports `.gz` gzip compressed files (my installation of 6.2 does).
Chris Johnsen
Vim handles editing files inside zip archives as well as gzipped files. It can also read and write encrypted files.
Dave Kirby
Why would anyone create such an editor with syntax highlighting? You couldn't use it to write software (or anything else) as only your editor could read it (when implemented as the question author described) :)
Tomas Markauskas
@Tomas: Assuming it was an interpreted language...
Mark
@Mark: bot no other software could interpret it
Tomas Markauskas
@Tomas: Yes, that's what I'm saying. *You* are assuming it's an interpreted langauge. A compiled language would produce a binary that could be read, assuming your editor could send the uncompressed version to the compiler.
Mark
+8  A: 

I want to use a algorithm to reduce memory used to save the particular text file

If you did this you would no longer have a text editor, but instead you would have created some sort of binary file editor.

The whole point of the text file format is that it is universal, meaning any text file can be open in any other text editor.

Blake7
A: 

thanks everyone I got what all of you'll are trying to say. Anyways all i wanted to do is instead of saving duplicates of a word make a hash table and store the address where it needs to be placed.

This was i wouldn't be storing the duplicates.

Yes and this would have become specific to a particular text editor. never realized that.

varunthacker
You should probably just edit your question to include notes like these. They do not really make sense as a separate answer.
Chris Johnsen
+7  A: 

Emacs handles compression transparently. Just create a text file with .gz extension. Emacs will automatically compress contents of the file during save operation, and decompress when you open the file next time.

Eugene Morozov