Re: Redim

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: alpine (alpine_don'tsendspam_at_mvps.org)
Date: 02/01/05


Date: Tue, 01 Feb 2005 11:15:19 -0700

On Tue, 1 Feb 2005 10:45:51 -0700, "Carl" <c@invalid.com> wrote:

>
>"alpine" <alpine_don'tsendspam@mvps.org> wrote in message
>news:lvevv0d3ljc29mo7ph7m44gtjl6t0096q0@4ax.com...
>> On Tue, 1 Feb 2005 09:57:41 -0700, "Carl" <c@invalid.com> wrote:
>>
>>>I am an amateur hobby programmer using VB6 Learner's Edition.
>>>I have a program that redimensions a one-dimension dynamic array according
>>>to the max number of items I may have in a list.
>>>
>>>I have successfully redimensioned the array at increasing values up to
>>>11,881,378.
>>>The next step is 308,915,778 but, when I redim to that value, I get an Out
>>>Of Memory error msg.
>>>
>>>I am using XP SP2 with 512 MB of memory.
>>>Maybe I am simply exceeding the upper limit of an array.
>>>
>>>Enlightenment appreciated.
>>>Carl
>>
>>
>> The maximum upper bound of an array is a Long value which would
>> translate to 2,147,483,647 so, you haven't exceeded that.
>> Furthermore, I believe you could set the lower bound to -2,147,483,648
>> which would double the available indices.
>>
>> What data type does this array consist of? I suspect it is your data
>> that is consuming the memory.
>>
>> HTH,
>> Bryan
>
>Bryan,
>Thanks. The array is dimensioned as a string. Dim TempArray() As String
>The Out Of Memory error occurs instantly, when the redim statement runs.
>I don't know how many bytes per element the OS is using, but even 2 will
>exceed my 512 MB or chip memory.
>As noted in my response to Jan, I thought the OS would use the hard drive as
>aux memory, but maybe not.
>Carl

I would guess that VB is attempting to allocate enough memory to copy
the entire contents of the array to a new cohesive memory block and
this is where the failure occurs. ReDimensioning arrays to a larger
size is expensive for this very reason. A best practice is to
dimension the array to the maximum size you will use the first time
you ReDim it and then remove any extra elements once you have all of
the data you want in the array.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas



Relevant Pages

  • 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)
  • Re: not enough storage... error using GetRows
    ... > array only contained ~150,000 rows. ... It took 19 minutes for GetRows to return (db ... and the prog had consumed 200MB of memory. ... The first one allocates some 180MB, the next two only allocate about 47MB ...
    (microsoft.public.vb.database.ado)