C
Cool Guy
How could I optimize the following method, whose purpose is to concatenate
two byte arrays?
public static byte[] ConcatBytes(byte[] a, byte[] b)
{
byte[] result = new byte[a.Length + b.Length];
uint i;
for (i = 0; i < a.Length; i++)
{
result = a;
}
for (i = 0; i < b.Length; i++)
{
result[i + a.Length] = b;
}
return result;
}
You see, my program uses this method, and to it, it passes two very large
(perhaps in the hundreds of megabytes) byte arrays. This method takes
MINUTES to run in this case.
two byte arrays?
public static byte[] ConcatBytes(byte[] a, byte[] b)
{
byte[] result = new byte[a.Length + b.Length];
uint i;
for (i = 0; i < a.Length; i++)
{
result = a;
}
for (i = 0; i < b.Length; i++)
{
result[i + a.Length] = b;
}
return result;
}
You see, my program uses this method, and to it, it passes two very large
(perhaps in the hundreds of megabytes) byte arrays. This method takes
MINUTES to run in this case.