Re: Out of Memory Problem in VB 6.0 Application.
- From: "Someone" <nobody@xxxxxxx>
- Date: Thu, 22 Sep 2005 23:43:00 -0400
I just remembered that dynamic arrays are pointers to SAFEARRAY structure,
which is 24 bytes in length. So memory usage is as follows:
' 12 Bytes
Public Type TestType
p1 As Long
p2 As Long
p3() As Double ' 4 bytes pointer only
End Type
Public testVar() As TestType
Redim testVar(1 To 60000) As TestType
' Total memory usage now =
' 24 + 60000*12 + 60000 * 24 = 2,160,024 Bytes
For i = 1 To 60000
Redim testVar(i).p3(1 To 500) As Double
Next
' Total memory usage now =
' 2,160,024 + 8 * 500 * 60000 = 242,160,024 Bytes
I used Excel for the last line :-)
Here are some details about how VB stores dynamic arrays:
http://support.microsoft.com/default.aspx?scid=kb;en-us;205277#XSLTH4162121122120121120120
Also:
http://support.microsoft.com/kb/199824/
"Michael C" <mculley@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ubd0q49vFHA.916@xxxxxxxxxxxxxxxxxxxxxxx
> "Mike Williams" <Mike@xxxxxxxxxxxxxxxxx> wrote in message
> news:dgp6ph$39v$1@xxxxxxxxxxxxxxxxxxxxxxx
>> I don't think so, Michael. Try this:
>>
>> Option Explicit
>> Private Type test
>> p1 As Long
>> p2 As Long
>> p3(1 To 500) As Double
>
> Of course, that's a fixed size array. If you declare a dynamic array, as
> Peri did, it will be a pointer. If you think about it, having a dynamic
> array inline with the type would be impossible (or very difficult) becuase
> the elements would not be evenly spaced in memory and higher elements
> would need to be moved every time you resized the array.
>
>> By the way, thanks for the info about VB arrays requiring a contiguous
>> block of memory. I'm
>> still a little confused about it though, because on my system I can
>> create a massive array that
>> requires much more real memory than I have on board and that can actually
>> approach the total of
>> real memory and swap file (on disk) memory. So can I take it that Windows
>> memory management is
>> able to treat a block of real RAM and a separate block of swap file (on
>> disk) as one complete
>> contiguous block, and that the CopyMemory API would do so also? Just
>> wondering.
>
> Just think of it as 2gigs of ram that you have at your disposal. It
> doesn't matter if that's real ram or swap file it's still 2 gigs available
> to your app. Windows and the cpu goes through some tricks to make your app
> think it's got this one big continuous area of ram. To confuse matters
> more the 2 gigs won't map directly to the same addresses in ram, eg
>
> addres 0 to 127 might be in a swap file
> 128 to 255 might be at 0x10000 in ram.
>
> The problem you get is if you then allocate some small chunks of that 2
> gigs at, say, 1 meg spacing all the way through the 2 gig, then you
> wouldn't be able to allocate anything bigger than 1 meg even though you've
> used up very little space.
>
> Michael
>
.
- References:
- Out of Memory Problem in VB 6.0 Application.
- From: Peri
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Peri
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Michael C
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Peri
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Mike Williams
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Peri
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Michael C
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Peri
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Mike Williams
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Mike Williams
- Re: Out of Memory Problem in VB 6.0 Application.
- From: Michael C
- Out of Memory Problem in VB 6.0 Application.
- Prev by Date: Re: Capture the Computer Desktop
- Next by Date: Re: Out of Memory Problem in VB 6.0 Application.
- Previous by thread: Re: Out of Memory Problem in VB 6.0 Application.
- Next by thread: Re: Out of Memory Problem in VB 6.0 Application.
- Index(es):
Relevant Pages
|