Best way to represent formatted text in memory? C++ -
I'm writing the original text editor, okay this is actually an editing control box where I want to write code, numeric Mann and expression for my main program
The way I am currently doing it is that I keep editing character control under control. In the editing control I have a class that divides the string into a 'glides' such as words, numbers, line breaks, tabs, draft tokens, etc. For example, the word glyph is a string representing the literal word and a small integer, which represents the number of white spaces located on the rear. When calculating script wrapping, the glyph also contains the necessary information.
For example, the text line "My name is Carl" is equal to a linked list of such glyphs: Nullinglif. Word traveler (â ???? maia ????, 1 white spot) is a ???? Word gallery (â ???? name, ????, 1 white location) a ???? Word Gleef (one is virtual, 1 white spot) a ???? Word Travel (â ???? curl ????, whitespace 0) Zero.
Therefore, instead of storing the string in memory in the form of continuous blocks of characters (or WCHAR), it is stored in small parts, which can potentially lead to many small allocation and deallocations.
My question is; Should it be related to pile fragmentation while doing this? Do you have any suggestions on making it more efficient? Or is there a completely different way of doing this? :)
PS I'm working on Win7 in C ++
Should you be worried about fragmentation? The answer is that how much your documents are (e.g., the number of words), and how much will be edited and depending on the nature of these edits, the outlook you mentioned may be appropriate for a static (read only) document. , Where you can "parse" the document once, but I think the proper work behind the scenes will be to the right to maintain your data structure In addition, the user is making an arbitrary edit, besides, you have to decide what "word" is, which is not necessarily clear / consistent in every case. For example, is "hard work" a word or two? If this is the one, does it mean that you will not ever wrap the word on the hyphen? Or, consider this matter where one word "one word" will not fit on one line. In that case, will you point only, or do you want to force the words to break completely?
will store my recommended text as a block, and store the line separately (text block as offset), then recalculate the line breaks as per the requirement of each time change . If you are worried about reducing the number of fragmentation and allocation / distribution, then you can allocate fixed-size blocks and then manage memory within those blocks. Here's what I have done. :
-
The text is stored as a block of characters, but instead of having a single section for the entire document, I maintain a linked list that always blocks 4KB (or Ni, 4 single byte characters, or 2K WCHARs) are allocated. In other words, the text is stored as a linked list of arrays, where each array is allocated for a continuous size.
-
Each block keeps track of how much space (i.e.,
-
if inserting one or more characters, if the place is in the existing block, So I can get the memory inside the blocks (no allocation / deallocation required) If there is no available space in the existing block, but the location is available in the adjacent block, then I do not require existing blocks (no allocation / deallocation) If you can find the memory between If I'm full, then only I will assign a new 4KB block and add it to the appropriate position in the linked list.
-
When removing one or more characters, To move the storage (max 4KB) instead of the document text, I may also need to delete and remove a block that is completely empty.
- < P> I have some "garbage" to organize empty space at the right time Archive ". It is quite straightforward and runs from one block to the other so that some blocks become empty and can be removed.
The OS and / or runtime From the library perspective, all the allocation / delocution is the same size (4 KB), so there is no fragmentation. And since I manage the contents of that memory, I can save the fragmentation within my allocated space by transferring the memory content to eliminate the wasted space. The other advantage is that it reduces the number of alloc / dealloc calls, which may be subject to performance concerns depending on the allocator you are using. Therefore, this speed is optimized for both and size - how often that is there? : -)
Comments
Post a Comment