Re: ReDim'ed Array size

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



dpb escribió:

Dynamic allocation delayed to assignment, otoh, while perhaps convenient, does have an associated overhead at run time with it that can be significant and could potentially be a real bottleneck causing much memory thrashing and needless allocation/deallocation and copying as arrays grow. It also leads to possibilities of out-of-memory problems owing to memory fragmentation. So, there is a price; not likely to be major for smaller applications but at least worthy to be aware of the potential problems.

If they can raise an error when you try to access an index out of bound, they are already checking the bounds. Then, to automatically redim the array instead of raising the error (just when writing) should not be an overhead (because anyway you'll have to do it in your code).

As for zero- vis a vis one-based array indexing, that again, is a choice that has many reasons for being one or the other--there are historical reasons of compatibility as well as applications where one or the other makes common sense.

I think it's a remain from the old days and also an inheritance from low level languages, but it's not good for a high level language.
A high level language must be rather friendly with the programmer... and humans count starting with 1.

Think of signal processing for sampled time series or frequency spectra where it's quite logical that 0 index is associated w/ either time zero or the DC (zero frequency) entry as simply one example for 0-based.

OK, you have some cases where 0 is the better and less confusing choice, but in the most of the cases 1 is the less confusing choice.

The 'Option Base' declaration could serve to set the dafault lower bound to 0, the opposite as it's in VB6.

Meanwhile, if one is doing record-based tracking, then 1-thru-N makes more sense than 0-thru-(N-1). Again, it isn't a case of right or wrong, it's what fits the situation.

Yes, as I already said, I agree. But at least for me, the most of the situations I have favor 1.
The most of the times you have the array with a list of elements, and those elements represent something, like windows handles, images, customers, rows, etc.

How many customers do you have? Let me see... 0, 1, 2, 3, 4... 5!
No... it's not 'normal' to count like that.

And, back to the spectral frequency example, for theoretical reasons for some purposes it makes sense to keep the symmetric (about DC) spectral components and so indices from -N/2 to +N/2 are handy (not to mention in VB the ability to double the size of arrays allowable since there isn't an unsigned integer to use as an array index to allow (1 To LargestIntegerOfSize-1) as a possibility w/o the workaround).

IOW, there isn't one stroke for all boats and there are reasons for the choices made in various programming languages.

--
.



Relevant Pages

  • Re: dgemm subroutine in BLAS - I think Ive cracked the difference, please confirm
    ... > see what I'm talking about), so in the current state of memory allocation, ... padding for performance reasons - a memory subsystem might work much better ... so you would perform a 1024x1024 FFT on a 1025x1024 array ...
    (comp.lang.fortran)
  • 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)