Click here to Skip to main content
15,914,419 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help add new section to this config please Pin
PIEBALDconsult16-Sep-11 17:52
mvePIEBALDconsult16-Sep-11 17:52 
QuestionSpeed of execution Pin
Kevin1316-Sep-11 5:10
Kevin1316-Sep-11 5:10 
AnswerRe: Speed of execution Pin
Simon Bang Terkildsen16-Sep-11 5:54
Simon Bang Terkildsen16-Sep-11 5:54 
GeneralRe: Speed of execution Pin
Kevin1316-Sep-11 6:43
Kevin1316-Sep-11 6:43 
AnswerRe: Speed of execution Pin
Matt Meyer16-Sep-11 6:11
Matt Meyer16-Sep-11 6:11 
GeneralRe: Speed of execution Pin
Kevin1316-Sep-11 6:34
Kevin1316-Sep-11 6:34 
GeneralRe: Speed of execution Pin
Matt Meyer16-Sep-11 7:02
Matt Meyer16-Sep-11 7:02 
AnswerRe: Speed of execution Pin
AspDotNetDev16-Sep-11 7:02
protectorAspDotNetDev16-Sep-11 7:02 
You can use loop unwinding.

Alternatively, rather than indexing the pointer, you can just increment it by one (ptr++) each loop iteration and use a while loop that only checks if the pointer you are currently at matches the ending pointer.

You can also combine the two techniques. Would go something like this (some syntax and values may be wrong, but you get the idea):
C#
byte* ptr = data;
byte* ptrEnd = data;
ptrEnd += (size - (size % 10));
while (ptr != ptrEnd)
{
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
    *ptr = 128; ptr++;
}
ptrEnd += (size % 10);
while(ptr != ptrEnd)
{
    *ptr = 128; ptr++;
}

I think there is also some more compact (and hard to understand, but maybe faster) syntax, but I forget it exactly. Something like this:
C#
*(++ptr) = 128;   // Maybe this?
*(ptr++) = 128;   // Or was it this?

I think C++ C# also has an optimized array.copy function. You can fill in an array of, say, 100 values, then copy that to the "data" array a bunch of times. Or maybe you can copy the array to itself a bunch of times, each time doubling the number of elements you can copy. Would go something like this (I can't be bothered looking up the syntax right now):
C#
Array.Copy(data, 0, length, data, length, length);

That would be 1 iteration in a loop... you'd obviously have to change the value of length each iteration. And you'd have to account for edge conditions. And it would only be useful if you were really filling the entire array with the same value.
Martin Fowler wrote:
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

AnswerRe: Speed of execution Pin
Luc Pattyn16-Sep-11 7:18
sitebuilderLuc Pattyn16-Sep-11 7:18 
AnswerRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 9:51
professionalEddy Vluggen16-Sep-11 9:51 
GeneralRe: Speed of execution Pin
AspDotNetDev16-Sep-11 10:38
protectorAspDotNetDev16-Sep-11 10:38 
AnswerRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 11:03
professionalEddy Vluggen16-Sep-11 11:03 
GeneralRe: Speed of execution Pin
AspDotNetDev16-Sep-11 11:20
protectorAspDotNetDev16-Sep-11 11:20 
AnswerRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 11:33
professionalEddy Vluggen16-Sep-11 11:33 
NewsRe: Speed of execution Pin
Eddy Vluggen16-Sep-11 13:44
professionalEddy Vluggen16-Sep-11 13:44 
QuestionUndo functionality for Node rename in TreeView Pin
Nyanoba16-Sep-11 1:28
Nyanoba16-Sep-11 1:28 
AnswerRe: Undo functionality for Node rename in TreeView Pin
BillWoodruff16-Sep-11 2:26
professionalBillWoodruff16-Sep-11 2:26 
AnswerRe: Undo functionality for Node rename in TreeView Pin
BobJanova16-Sep-11 3:51
BobJanova16-Sep-11 3:51 
GeneralRe: Undo functionality for Node rename in TreeView Pin
BillWoodruff16-Sep-11 17:01
professionalBillWoodruff16-Sep-11 17:01 
GeneralRe: Undo functionality for Node rename in TreeView Pin
Nyanoba19-Sep-11 19:22
Nyanoba19-Sep-11 19:22 
QuestionShow a hidden console again? Pin
Don Rolando15-Sep-11 22:49
Don Rolando15-Sep-11 22:49 
AnswerRe: Show a hidden console again? Pin
V.15-Sep-11 23:16
professionalV.15-Sep-11 23:16 
GeneralRe: Show a hidden console again? Pin
Don Rolando15-Sep-11 23:18
Don Rolando15-Sep-11 23:18 
GeneralRe: Show a hidden console again? Pin
V.15-Sep-11 23:37
professionalV.15-Sep-11 23:37 
GeneralRe: Show a hidden console again? Pin
Don Rolando16-Sep-11 0:23
Don Rolando16-Sep-11 0:23 

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.