how to realloc arrays?

  • Thread starter Thread starter Egor Yu. Shkerin
  • Start date Start date
E

Egor Yu. Shkerin

Hello.
Please tell me how can I grow size of arrays?
Now I do something like that:

sbyte [] a = new sbyte[ 1 ];
for( int i = 2; i < 10; i++ )
{
sbyte [] new_a = new sbyte[ i ];
a = new_a;
}

But I fill that it will be memory leak.
How can I free memory taken with "a" variable?
Or maybe I do something stupid? Then please let me know how should I realloc buffer.
 
Please tell me how can I grow size of arrays?
Just define a new array of desired size. You may need to use
Array.CopyTo to copy the content from the old array to the new one.
Don't worry about memory, the Garbage Collector will.

Also consider using the ArrayList instead.

Hope that helps,
Thi
 
Back
Top