I have an in-memory byte[] and need to locate the offset where 13 and 10 are. I will then use the following to extract that line:
String oneLine = Encoding.ASCII.GetString(bytes, 0, max);
What is the fastest way to search for the two bytes on a x64 bit computer? ..and convert it to a string?
Is there anything I can do other than iterating through each byte, scanning for 13 and then scan for 10?
// Disclaimer:
// This is just for my curiosity. Perhaps I'll gain a better understanding of
// how .NET interfaces with RAM, the CPU instructions related to comparisons, etc.
//
// I don't suspect a performance problem, but I do suspect a lack of understanding
// (on my part) on how C# does low-level operations.
yourString.IndexOf(Environment.NewLine)? Genuinely curious...ulong*, and for each 8-byte block use SWAR to test whether it contains a 13. If it does, scan from the beginning of that block for 13,10, and well you can make the rest up. Whether that's faster, well, who knows. But it's something you could try, if necessary.