David,[color=blue]
> Is this sequence about as efficient as I can get for sometimes expanding[/color]
an[color=blue]
> array?[/color]
For the most part yes.
You could do as the ArrayList & StringBuilder classes do.
Over allocate the array, and keep track of how many items are actually in
the array. When the array gets full, then you double it in size. Of course
that may be what you are already doing ;-)
There was a discussion about creating an new ArrayList like class for
structures in the vb.dotnet.technical newsgroup (on the news.devx.com news
server). Look for a thread titled 'Dynamic array of structure variables,
starting 2 Aug 2003.
http://news.devx.com/cgi-bin/dnewswe...tnet.technical
I gave a start of a class to create a dynamic array of structures, that over
allocates the underlying array.
Hope this helps
Jay
"David Rogers" <drogers@NOSPAM.fhcrc.org> wrote in message
news:%23aw2ZS9eDHA.560@tk2msftngp13.phx.gbl...[color=blue]
> Is this sequence about as efficient as I can get for sometimes expanding[/color]
an[color=blue]
> array?
>
> MyClass [] MyFunc()
> {
> MyClass [] result = new MyClass [0];
>
> {
> // Do stuff that might possibly allocate an array and put entries[/color]
in[color=blue]
> it
> // This path is usually executed
> // ...
> result = new MyClass[numEntries];
> }
>
> {
> // Do stuff that might possibly add more entries to the previously
> allocated array
> // This path may be executed, but not usually
> // ...
> newResult = new MyClass[result .Length + newNumEntries];
> result .CopyTo(newResult , 0);
> result = newResult ;
> }
>
> return result;
> }
>
>[/color]