Re: Remove First Row from Variant Array FAST?
From: Harlan Grove (hrlngrv_at_aol.com)
Date: 08/20/04
- Next message: Harlan Grove: "Re: Delete empty array columns"
- Previous message: RB Smissaert: "Re: Delete empty array columns"
- In reply to: R Avery: "Re: Remove First Row from Variant Array FAST?"
- Next in thread: Peter T: "Remove First Row from Variant Array FAST?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 19 Aug 2004 23:36:00 -0700
"R Avery" <ravery74@yahoo.co.uk> wrote...
>Ok. Let me clarify FAST. When I say manipulating the SAFEARRAY so that
>it thinks there is 1 fewer element in the array and incrementing the
>pointer to the first item, if this is possible, I expect it to take
>0.0001 or less seconds to do this for an array with 10million or
>10billion or more items. Reallocating an entire array for 9,999,999,999
>elements and copying them over is not FAST. 0.0001 seconds is FAST.
Unlikely you could manipulate the SAFEARRAY construct as you'd like. The key
part of the SAFEARRAY structure is the pointer to the data, meaning that the
data is NOT stored in the SAFEARRAY structure itself. Depending on exactly
how VBA manages pointers and memory allocation, you could thoroughly fubar
your system with memory leaks by manipulating the pointer directly.
I suppose it'd be possible for you to create a new SAFEARRAY structure,
modify the dimension bounds, and assign the pointer to the desired location
in the original SAFEARRAY's allocated memory. JUST DON'T FREE THAT ARRAY!
>Is it possible to do delete the first item in a 1-D array (so that the
>2nd element now becomes the 0th index) or to delete the first row in a
>2-D array (so that the 2nd row now becomes the 0th index in the first
>dimension) FAST?
Who knows? But without a doubt the fastest way to *use* subarrays of an
existing array is just to use the existing array AS-IS with suitable new
starting and ending indices. For example, addressing the middle third of the
array a(1 To 150000) would ideally be done as
For i = 50001 To 100000
x = f(a(i))
Next i
There are obvious ways to generalize this and make it more flexible.
- Next message: Harlan Grove: "Re: Delete empty array columns"
- Previous message: RB Smissaert: "Re: Delete empty array columns"
- In reply to: R Avery: "Re: Remove First Row from Variant Array FAST?"
- Next in thread: Peter T: "Remove First Row from Variant Array FAST?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|