Re: CObArray with huge number of elements

Tech-Archive recommends: Fix windows errors by optimizing your registry



SetSize(0, 100000);

The nGrowBy parameter, the second parameter, says that the number of elements will be
increased. The first allocation will allocate space for 100000 elements, and if you use
all of those, another 100000 will be allocated (but the GetSize value reflects the ACTUAL
number of elements). Then the Add will not need to do new storage allocation and a
complete copy until it hits the SetGrowBy boundary, then a massive new chunk will be
allocated. When you are all done you can call FreeExtra if you don't want to waste the
unused space that has been allocated (which may not matter).
joe

On Fri, 1 Jul 2005 21:05:53 +0100, "phil" <phil@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

>Hope someone can help
>
>I need to hold potentially huge numbers of CObject pointers in an array
>
>As a simple test I tried this...
>CObject *this = new MyObject();
>CObArray things;
>for (long y=0;y<1000000;y++)
> things.Add(object); // just add the same one repeatedly
>
>this gets progressivly slower until it grings to a halt at about 200,000
>elements
>
>If i try this
>CObject *this = new MyObject();
>CObArray things;
>things.SetSize(1000000); // set the size before hand
>
>for (long y=0;y<1000000;y++)
> things[y]=object;
>
>this goes like the clappers - no problem except I dont know how many I need
>before hand
>
>
>
>Does anyone know of a good method for holding a 'vector' of huge numbers of
>items without causing what looks like an exponetial slow down.
>
>Any help given will be much appreciated.
>
>Phil
>

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.


Quantcast