S
Sin Jeong-hun
Here are my imaginary codes:
void DoSomething()
{
FileStream fs;
Packet p;
...
fs.Write(p.Body, 0, p.Body.Length);
}
class Packet
{
byte[] EntireData;
....
public Body
{
get
{
byte[] rtn = new byte[EntireSize - HeaderSize];
Array.Copy(EntireData, HeaderSize, rtn, BodySize);
return rtn;
}
}
}
When we write the body of the packet to a file inside DoSomething, we
just want to read the content of the Body. But I guess this code is
very inefficient because it makes another copy of the long data. If I
was using C, I could just return the address by adding HeaderSize to
the pointer to the EntireData.
How could I make the Packet class above more efficient? Any
suggestions would be welcome. Thank you.
void DoSomething()
{
FileStream fs;
Packet p;
...
fs.Write(p.Body, 0, p.Body.Length);
}
class Packet
{
byte[] EntireData;
....
public Body
{
get
{
byte[] rtn = new byte[EntireSize - HeaderSize];
Array.Copy(EntireData, HeaderSize, rtn, BodySize);
return rtn;
}
}
}
When we write the body of the packet to a file inside DoSomething, we
just want to read the content of the Body. But I guess this code is
very inefficient because it makes another copy of the long data. If I
was using C, I could just return the address by adding HeaderSize to
the pointer to the EntireData.
How could I make the Packet class above more efficient? Any
suggestions would be welcome. Thank you.