Re: Remove First Row from Variant Array FAST?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Harlan Grove (hrlngrv_at_aol.com)
Date: 08/20/04


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.



Relevant Pages

  • Re: SafeArrays problem between Fortran and VB .Net
    ... | End Interface ... By declaring that intData is an Integer, POINTER:: you tell the ... compiler to pass a SAFEARRAY**, ... | a method expecting an array of rank 1." ...
    (comp.lang.fortran)
  • interop: Passing pointer to COM to efficiently receive large data chunk
    ... I'm writing COM to expose some unmanaged imagery generation functions to c#. ... process(SAFEARRAY* bytes) ... does this pass a pointer, or is it marshalled? ... example 2: using fixed array size ...
    (microsoft.public.dotnet.framework.interop)
  • Re: using arrays as function parameters, with c#
    ... The SAFEARRAY I receive has a cdims of 44960, a cbElements of 0, null data, ... interface IPs3Bridge: IDispatch { ... System.Array array = System.Array.CreateInstance,2); ... very buggy with attributed ATL, and I'm shy to use it in Visual Studio ...
    (microsoft.public.vc.atl)
  • Re: theoretical question
    ... Igor described you shouldn't be using a safe array. ... it's as easy as having the client pull it. ... I want to get the acquired image into a safearray and fire an event ... the event handler to add to the queue. ...
    (microsoft.public.vc.atl)
  • Re: ATL/COM memory management
    ... > Property of type SAFEARRAY, then assess the data array in the SAFEARRAY to ... the IDL but requires an extra level of indirection in the C++ header. ... lIndex, double *pdTheValue); ...
    (microsoft.public.vc.language)