Click here to Skip to main content
15,894,410 members
Home / Discussions / C#
   

C#

 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Christian Graus9-Jun-08 17:16
protectorChristian Graus9-Jun-08 17:16 
JokeRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
PIEBALDconsult9-Jun-08 17:26
mvePIEBALDconsult9-Jun-08 17:26 
GeneralRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
MarkB7779-Jun-08 17:49
MarkB7779-Jun-08 17:49 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Joe Woodbury9-Jun-08 19:30
professionalJoe Woodbury9-Jun-08 19:30 
AnswerRe: Will Using Console.Beep(); Too Much Damage Your Computer? Pin
Ashfield9-Jun-08 21:24
Ashfield9-Jun-08 21:24 
QuestionBind a Datatable With an Hyperlink Column To a GridView Pin
HatakeKaKaShi9-Jun-08 16:51
HatakeKaKaShi9-Jun-08 16:51 
QuestionBinary Reader Scanning for string Pin
Jammer9-Jun-08 15:12
Jammer9-Jun-08 15:12 
AnswerRe: Binary Reader Scanning for string Pin
Insincere Dave9-Jun-08 17:21
Insincere Dave9-Jun-08 17:21 
I don't think the code you posted is that bad. You could improve it a little by keeping track of the previous characters so you don't need to reset the position. I did some unscientific tests using a 20mb MemoryStream with the data part at the end.

Original 1x
Keep track of previous characters using an array like a circular queue. ~1.8x speedup
Same as above but treating characters as bytes. ~8x speedup to original
Read whole file into byte[]. ~20x speedup

long pos = 0;
byte[] previous = bReader.ReadBytes(4);

for (long i = bReader.BaseStream.Position; i < length; i++)
{
    byte current = bReader.ReadByte();
    previous[pos++ % 4] = current;

    if (previous[pos % 4] == 'd' && previous[(pos + 1) % 4] == 'a' && previous[(pos + 2) % 4] == 't' && previous[(pos + 3) % 4] == 'a')
    {
        dataChunk.sChunkID = "data";
        dataChunk.dwChunkSize = bReader.ReadUInt32();
        return;
    }
}


It would seem the text encoding has the biggest impact, I couldn't find many wav files to test so I don't know if my code behaves any better than yours does, of the ones I tested the actual speed impact was negligible maybe something else was causing the slowdown?
Check the files that aren't working in a hex editor (in VS Open File > Open Dropdown > Binary Editor) and make sure you take care between int/unit/long for positions, file lengths e.t.c and the endianess of what your reading.

Think you've already seen this article.
GeneralRe: Binary Reader Scanning for string Pin
Jammer10-Jun-08 3:22
Jammer10-Jun-08 3:22 
AnswerRe: Binary Reader Scanning for string Pin
Guffa10-Jun-08 12:02
Guffa10-Jun-08 12:02 
GeneralRe: Binary Reader Scanning for string Pin
Jammer10-Jun-08 12:17
Jammer10-Jun-08 12:17 
GeneralRe: Binary Reader Scanning for string Pin
Jammer10-Jun-08 13:36
Jammer10-Jun-08 13:36 
GeneralRe: Binary Reader Scanning for string Pin
Guffa10-Jun-08 20:32
Guffa10-Jun-08 20:32 
GeneralRe: Binary Reader Scanning for string Pin
Jammer11-Jun-08 9:21
Jammer11-Jun-08 9:21 
QuestionForm Inheritance Pin
Dirso9-Jun-08 13:31
Dirso9-Jun-08 13:31 
AnswerRe: Form Inheritance Pin
MarkB7779-Jun-08 13:48
MarkB7779-Jun-08 13:48 
GeneralRe: Form Inheritance Pin
Dirso9-Jun-08 14:32
Dirso9-Jun-08 14:32 
GeneralRe: Form Inheritance Pin
MarkB7779-Jun-08 16:16
MarkB7779-Jun-08 16:16 
GeneralRe: Form Inheritance Pin
Dirso10-Jun-08 2:05
Dirso10-Jun-08 2:05 
GeneralRe: Form Inheritance Pin
MarkB77710-Jun-08 2:28
MarkB77710-Jun-08 2:28 
GeneralRe: Form Inheritance Pin
Dirso10-Jun-08 2:47
Dirso10-Jun-08 2:47 
GeneralRe: Form Inheritance Pin
MarkB77710-Jun-08 2:59
MarkB77710-Jun-08 2:59 
GeneralRe: Form Inheritance Pin
Dirso10-Jun-08 10:30
Dirso10-Jun-08 10:30 
GeneralRe: Form Inheritance (still can't edit) Pin
Dirso10-Jun-08 12:20
Dirso10-Jun-08 12:20 
QuestionCalling an Extension method from another Extension method (C# 3.0) Pin
Rajesh Moriyani9-Jun-08 12:43
Rajesh Moriyani9-Jun-08 12:43 

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.