S
semedao
Hi,
I have some loop that should copy X amount of bytes to some byte[] buffer.
the byte buffer array is fixed length during the loop
but outside the loop the length can change.
the loop can be called also inside other loop...
If I have this code for example when
What will be better performance , to check for buffer length before
re-allocate it , or to re-allocate it every time?
what coast more? the Length property + if , or the allocating ? (if we speak
about 10-100 bytes memory , and that the call change it every 10 times)
fooA()
{
do
{
fooB(***some value that can change every call***);
}
}
fooB(int CurrentLength){
if(_buffer.Length != CurrentLength)
{
_buffer = new byte[CurrentLength];
}
do
{
_buffer = ....data....
}
}
I have some loop that should copy X amount of bytes to some byte[] buffer.
the byte buffer array is fixed length during the loop
but outside the loop the length can change.
the loop can be called also inside other loop...
If I have this code for example when
What will be better performance , to check for buffer length before
re-allocate it , or to re-allocate it every time?
what coast more? the Length property + if , or the allocating ? (if we speak
about 10-100 bytes memory , and that the call change it every 10 times)
fooA()
{
do
{
fooB(***some value that can change every call***);
}
}
fooB(int CurrentLength){
if(_buffer.Length != CurrentLength)
{
_buffer = new byte[CurrentLength];
}
do
{
_buffer = ....data....
}
}