Click here to Skip to main content
15,900,108 members
Home / Discussions / C#
   

C#

 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson30-Apr-24 3:14
professionalJörgen Andersson30-Apr-24 3:14 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson30-Apr-24 4:22
professionalJörgen Andersson30-Apr-24 4:22 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Rob Philpott30-Apr-24 4:27
Rob Philpott30-Apr-24 4:27 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
jschell30-Apr-24 12:17
jschell30-Apr-24 12:17 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson1-May-24 8:21
professionalJörgen Andersson1-May-24 8:21 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Jörgen Andersson1-May-24 8:49
professionalJörgen Andersson1-May-24 8:49 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Richard Deeming1-May-24 21:47
mveRichard Deeming1-May-24 21:47 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
trønderen2-May-24 6:50
trønderen2-May-24 6:50 
Richard Deeming wrote:
C#
ReadOnlySpan<char> input = "ABCD"; 
ReadOnlySpan<byte> bytes = System.Runtime.InteropServices.MemoryMarshal.AsBytes(input);
int value = System.Runtime.InteropServices.MemoryMarshal.Read<int>(bytes);
Will that compile to a single instruction, as you might see when using C/C++ casting?

If you want to treat 4 chars at a time by treating them as ints, this doesn't look like something that would save CPU cycles. I admit that I haven't tried to compile the code and studied the instructions generated.

Endianness isn't your only concern. Don't forget that UTF16, the internal character format of C#, also can contain surrogates and other funny elements.
jschell wrote:
So a value like "ABCD" can be cast directly to a 32 bit unsigned integer.
obviously expecting a result of 1 094 861 636, hex 41424344 on big-endian machines, 1 145 258 561, hex 44434241 on little-endian machines. With UTF16 representation, the value 4325441, hex 00420041, encodes only two characters, "AB", not four as the C++ programmer expected. (C# never used 8 bit char representation, so the C# should not expect that four chars are packed into a 32 bit int.)

Religious freedom is the freedom to say that two plus two make five.

GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Richard Deeming2-May-24 21:39
mveRichard Deeming2-May-24 21:39 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Rob Philpott2-May-24 23:57
Rob Philpott2-May-24 23:57 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
Richard Deeming3-May-24 0:39
mveRichard Deeming3-May-24 0:39 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
trønderen3-May-24 3:36
trønderen3-May-24 3:36 
GeneralRe: Performance of Switch case vs dictionary with delegates Pin
trønderen3-May-24 3:34
trønderen3-May-24 3:34 
Question3D графика Pin
Member 1381389024-Apr-24 19:16
professionalMember 1381389024-Apr-24 19:16 
GeneralRe: 3D графика Pin
Ralf Meier24-Apr-24 20:55
mveRalf Meier24-Apr-24 20:55 
AnswerRe: 3D графика Pin
Pete O'Hanlon24-Apr-24 20:58
mvePete O'Hanlon24-Apr-24 20:58 
GeneralRe: 3D графика Pin
Richard Deeming30-Apr-24 0:01
mveRichard Deeming30-Apr-24 0:01 
AnswerRe: 3D графика Pin
OriginalGriff24-Apr-24 21:47
mveOriginalGriff24-Apr-24 21:47 
QuestionHow to start creating a WinUI project ? Pin
Martin Adams 202324-Apr-24 2:54
Martin Adams 202324-Apr-24 2:54 
AnswerRe: How to start creating a WinUI project ? Pin
Richard MacCutchan24-Apr-24 3:45
mveRichard MacCutchan24-Apr-24 3:45 
GeneralRe: How to start creating a WinUI project ? Pin
Martin Adams 202324-Apr-24 6:02
Martin Adams 202324-Apr-24 6:02 
QuestionRe: How to start creating a WinUI project ? Pin
Richard MacCutchan24-Apr-24 6:43
mveRichard MacCutchan24-Apr-24 6:43 
AnswerRe: How to start creating a WinUI project ? Pin
Martin Adams 202324-Apr-24 6:44
Martin Adams 202324-Apr-24 6:44 
GeneralRe: How to start creating a WinUI project ? Pin
Richard MacCutchan24-Apr-24 6:51
mveRichard MacCutchan24-Apr-24 6:51 
GeneralRe: How to start creating a WinUI project ? Pin
Martin Adams 202324-Apr-24 7:13
Martin Adams 202324-Apr-24 7:13 

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.