On Tue, 11 Dec 2007 22:08:06 -0800, Tom <Th********@earthlink.netwrote:
[...]
#1) One important observation is that StreamReader correctly imports
ASCII text data files into a RichTextBox because it defaults to UTF-8.
Why is this confusing? My texts state that .Net uses Unicode(UTF-16)?
..NET uses UTF-16 internally, but it supports a wide range of text formats
for reading and writing. Even in situations where the default encoding
used to read a file doesn't work, you can specify an encoding yourself and
..NET will convert.
[...]
#2) StreamReader calls File.OpenText that has attribute CanSeek =
false. Thus the only other C# option I have found so far is to use
FileStream. Unfortunately FileStream supports the reading of bytes and
not lines. There was some happy dancing here when I figured out the
byte_array -string -RichTexBox conversion and input.
I don't think your effort with FileStream was lost, since you learned more
about using encodings to convert bytes to or from strings.
But you can in fact seek with a StreamReader. You just need to use the
BaseStream for seeking, calling DiscardBufferedData() on the StreamReader
after you seek to synchronize the StreamReader with the underlying stream.
[...]
#3) Using the thumb to "Position" the pointer within the file,
clearing the RichTextBox and performing another RichTextBox input is
level one performance. Being able to smoothly scroll in both
directions using a buffer would kick it up several notches.
[...]
Wiki references the following >>
http://www.winterdom.com/dev/dotnet/index.html
The above has a FileMap and Patch that looks promising ... I hope to
explore them soon and hopefully understand them. Yikes! Most likely
over my head.
Well, as Nicholas asked, how would you do it in C++? Assuming you're
familiar with the native Win32 memory mapping API, then assuming the
memory mapping libraries you found work in a similar fashion, I'd guess
they would be able to handle the buffering useful for better performance..
It kind of depends how elaborate the implementations are, especially with
respect to going backwards (would they pre-load data from the file that
precedes data you're reading?) I didn't actually look at the libraries,
so I obviously don't know.
Of course, you don't have to use memory mapping techniques. You could
buffer the file yourself, keeping decent-size blocks in a linked list or
even just referenced in a small array (one small enough that shifting the
array elements is a trivial, fast operation).
>
#4) A crude scrolling/thumb implementation simple scales the percent
thumb travel to that of the pointer being Positioned to that same
percentage of the file.Length. Some clever scroll and cursor event
trapping within the RichTextBox might can effectively reload the
RichTextBox ... but I suspect less than smooth operation. Even so,
viewing portions of a huge file quickly and without hogging resources
is a good thing. :)
I'm not really sure what you're asking here. The default minimum and
maximum range for a ScrollBar is suited to percentages, but you can set
the range to whatever you want, up to the range of the Int32 type. Is
there something you're looking to do other than just setting the Maximum
property to the file length?
Finally, I'll suggest that whatever you do, trying to do this with an
actual RichTextBox is always going to be on the slow side (because you
need to reset the text of the RichTextBox whenever you scroll), and
possibly even prone to UI oddities depending on how you do it (having your
own scrollbar rather than using the textbox's solves some issues, but may
introduce new ones). You may find that in the long run it makes more
sense to implement your own textbox control that supports the
virtualization you're looking for.
Or, for that matter, maybe someone already has. Have you looked to see if
a class like this already exists?
Pete