Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
QuestionCMD? Pin
Azel Low22-Nov-03 5:30
Azel Low22-Nov-03 5:30 
AnswerRe: CMD? Pin
leppie22-Nov-03 6:19
leppie22-Nov-03 6:19 
GeneralRe: CMD? Pin
Azel Low22-Nov-03 7:21
Azel Low22-Nov-03 7:21 
GeneralMR. Heath Stewart come in please Pin
nakey_yang22-Nov-03 2:21
nakey_yang22-Nov-03 2:21 
GeneralRe: MR. Heath Stewart come in please Pin
Heath Stewart22-Nov-03 4:15
protectorHeath Stewart22-Nov-03 4:15 
GeneralRe: MR. Heath Stewart come in please Pin
nakey_yang22-Nov-03 15:26
nakey_yang22-Nov-03 15:26 
GeneralRe: MR. Heath Stewart come in please Pin
Heath Stewart24-Nov-03 4:15
protectorHeath Stewart24-Nov-03 4:15 
GeneralRe: MR. Heath Stewart come in please Pin
nakey_yang24-Nov-03 20:02
nakey_yang24-Nov-03 20:02 
GeneralRe: MR. Heath Stewart come in please Pin
Heath Stewart25-Nov-03 2:57
protectorHeath Stewart25-Nov-03 2:57 
GeneralRe: MR. Heath Stewart come in please Pin
nakey_yang26-Nov-03 22:03
nakey_yang26-Nov-03 22:03 
GeneralRe: MR. Heath Stewart come in please Pin
Heath Stewart28-Nov-03 3:30
protectorHeath Stewart28-Nov-03 3:30 
GeneralRe: MR. Heath Stewart come in please Pin
nakey_yang1-Dec-03 14:57
nakey_yang1-Dec-03 14:57 
GeneralRe: MR. Heath Stewart come in please Pin
Heath Stewart1-Dec-03 18:27
protectorHeath Stewart1-Dec-03 18:27 
GeneralRe: MR. Heath Stewart come in please Pin
nakey_yang3-Dec-03 15:28
nakey_yang3-Dec-03 15:28 
GeneralRe: MR. Heath Stewart come in please Pin
Heath Stewart4-Dec-03 3:55
protectorHeath Stewart4-Dec-03 3:55 
GeneralGet Path & File name using OpenFileDialog Pin
Steve McLenithan22-Nov-03 1:57
Steve McLenithan22-Nov-03 1:57 
GeneralRe: Get Path & File name using OpenFileDialog Pin
Nick Parker22-Nov-03 2:04
protectorNick Parker22-Nov-03 2:04 
GeneralRe: Get Path & File name using OpenFileDialog Pin
Steve McLenithan22-Nov-03 2:12
Steve McLenithan22-Nov-03 2:12 
GeneralRe: Get Path & File name using OpenFileDialog Pin
leppie22-Nov-03 3:15
leppie22-Nov-03 3:15 
GeneralRe: Get Path & File name using OpenFileDialog Pin
Steve McLenithan22-Nov-03 4:36
Steve McLenithan22-Nov-03 4:36 
GeneralRe: Get Path & File name using OpenFileDialog Pin
Heath Stewart22-Nov-03 4:26
protectorHeath Stewart22-Nov-03 4:26 
leppie's right - what would you expect when opening such a large file?

Instead, read the file in blocks (streaming):
StreamReader reader = new StreamReader(openFileDialog1.FileName, true);
int read = 0;
char[] buffer = new char[4096];
do
{
  read = s.Read(buffer, 0, buffer.Length);
  Console.Write(buffer);
} while (read == buffer.Length);
Notice that I also use a StreamReader. Any TextReader or TextWriter derivites are optimized for text. The boolean in the StreamReader constructor actually attempts to determine if the text is ASCII, UTF7 or 8, or Unicode. If you use a stream, you have to know / determine the encoding yourself.

The main point, however, isthat you don't keep the entire file in memory. You dump the buffer and get more. Displaying a 200 MB file will take that much memory plus more - and if you read an ASCII file into a Char array, you'll waste even more memory because .NET stores characters and strings as Unicode - thus taking two bytes per character.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: Get Path & File name using OpenFileDialog Pin
Steve McLenithan22-Nov-03 4:34
Steve McLenithan22-Nov-03 4:34 
GeneralIcon Background Pixels Pin
Tristan Rhodes22-Nov-03 1:32
Tristan Rhodes22-Nov-03 1:32 
GeneralRe: Icon Background Pixels Pin
Heath Stewart22-Nov-03 4:34
protectorHeath Stewart22-Nov-03 4:34 
GeneralRe: Icon Background Pixels Pin
Tristan Rhodes22-Nov-03 7:17
Tristan Rhodes22-Nov-03 7:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.