Re: ReDim'ed Array size
- From: Eduardo <mm@xxxxxx>
- Date: Thu, 15 Oct 2009 23:59:09 -0300
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.
--
- Follow-Ups:
- Re: ReDim'ed Array size
- From: dpb
- Re: ReDim'ed Array size
- References:
- ReDim'ed Array size
- From: xytsrm
- RE: ReDim'ed Array size
- From: xytsrm
- RE: ReDim'ed Array size
- From: xytsrm
- Re: ReDim'ed Array size
- From: Tom Shelton
- Re: ReDim'ed Array size
- From: xytsrm
- Re: ReDim'ed Array size
- From: Tom Shelton
- Re: ReDim'ed Array size
- From: Jeff Johnson
- Re: ReDim'ed Array size
- From: Eduardo
- Re: ReDim'ed Array size
- From: Bill McCarthy
- Re: ReDim'ed Array size
- From: Eduardo
- Re: ReDim'ed Array size
- From: Scott M.
- Re: ReDim'ed Array size
- From: Eduardo
- Re: ReDim'ed Array size
- From: dpb
- ReDim'ed Array size
- Prev by Date: Re: Crossing the YearEnd Zone
- Next by Date: Re: ReDim'ed Array size
- Previous by thread: Re: ReDim'ed Array size
- Next by thread: Re: ReDim'ed Array size
- Index(es):
Relevant Pages
|