Wednesday, 7 August 2013

read the huge text file in chunks by chunks by scollbar

read the huge text file in chunks by chunks by scollbar

Hi i have read this question :
Reading very large text files, should I be incorporating async?
in the answer , its said that :
==============================================
Update - Paging/Chunking
You need to read the text file in chunks of one page, and allow the user
to scroll through the "pages" in the file. As the user scrolls you read
and present them with the next page.
Now, there are a couple of things you can do to help yourself, always keep
about 10 pages in memory, this allows your app to be responsive if the
user pages up / down a couple of pages very quickly. In the applications
idle time (Application Idle event) you can read in the next few pages,
again you throw away pages that are more than five pages before or after
the current page.
Paging backwards is a problem, because you don't know where each line
begins or ends in the file, therefore you don't know where each page
begins or ends. So for paging backwards, as you read down through the
file, keep a list of offsets to the start of each page (Stream.Pos), then
you can quickly Seek to a given position and read the page in from there.
If you need to allow the user to search through the file, then you pretty
much read through the file line by line (remembering the page offsets as
you go) looking for the text, then when you find something, read in and
present them with that page.
====================================================================
assume that i have a larg text file (1 gb) and winform with richtextbox
and scrollbar.
please help me with example code to do this.
thanks alot.

No comments:

Post a Comment