Re: newbie: array passing problem



"dpb" <none@xxxxxxx> wrote in message news:f7bgmc$r92$1@xxxxxxxxxxx

It is the latter that is what OP was trying to avoid (the double
index addressing issue, to be precise) and I wouldn't say it
was "worrying" me, only that you can't meet OP's actual
question/want/desire in VB of being able to precisely mimic
his existing Fortran code in VB.

Perhaps I didn't make myself very clear in my previous post (I do tend to waffle!), but you actually *can* do that in VB (pass a reference to a specific "column" of a 2D array to a subroutine in such a way that the subroutine only needs to use a single index). You can do it with a "column", but not with a "row", but perhaps that might suits the OP's needs (there are many applications I can think of in which it would). For example (and making sure we're both talking about the same thing in respect of columns and rows) suppose you have a 2D array of the form:

myData (rows, columns) as Single

.. . . and you declare it like this:

Dim myData(1 To 50000, 1 To 100) As Single

You can set up a small SAFEARRAY structure specifying that it is a one dimension array with 50000 elements and with each element occupying four bytes (the same number of bytes as a Single) and with its data area starting at the same memory location as the start of column 99 (for example) of the myData array. The structure itself of course only takes up about twenty or so bytes of memory. You can then point that SAFEARRAY structure at an uninitialised VB array of Singles (for example Dim myColumn() as Single) and as far as VB is concerned the myColumn array will be a one dimension array of 500 variables of the type Single. Your code (or the code in a subroutine to which you pass the myColumn array) can deal with the myColumn array using just one index, such as, for example:

myColumn (333) = 3.1416

But the things it does to the individual elements of the myColumn array (which don't really exist in their own right as separate entities!) will actually get done to the elements of the 99th column of the two dimensional myData array, so the above code (in this specific example) would actually be setting myData(333, 99) to 3.1416, because it was the starting address of the 99th column that we specified in the SAFEARRAY structure. Isn't that exactly what the OP wants?

You cannot do the same for "rows" of course, because a column is in a contiguous block of memory whereas of course a row is not. There are a few "tricks" I can think of to overcome that limitation, but they're not really doing exactly what the OP was after so I won't go down that road. The system works fine for passing an individual column of a two dimension array to a funtion though, and it does so without shifting blocks of memory around, so it might suit the OP's requirements.

Mike



.



Relevant Pages

  • Re: newbie: array passing problem
    ... Mike Williams wrote: ... Perhaps I didn't make myself very clear in my previous post, but you actually *can* do that in VB (pass a reference to a specific "column" of a 2D array to a subroutine in such a way that the subroutine only needs to use a single index). ... You can then point that SAFEARRAY structure at an uninitialised VB array of Singles as Single) and as far as VB is concerned the myColumn array will be a one dimension array of 500 variables of the type Single. ...
    (microsoft.public.vb.general.discussion)
  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: High Memory Consumption of Classes and Arrays
    ... Only the array itself has overhead. ... memory as a reference type. ... > least consume 40 bytes of memory. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.mfc)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.language)

Loading