Hi,

I defined A as an array in this way:

Dim A() as string

It is an array with unspecified array size.

Somewhere in the programme, I define the array size like this:

ReDim A(10)

When I redim, does it mean some memory is immediately allocated for
this array or does memory is allocated for this array ONLY when I
define the elements as well, like, for example,

ReDim A(10)
A(1)="apple"
A(2)="orange"
....

?

Thanks.

Mike

Re: Question about memory allocation by Tony

Tony
Sun Jul 13 00:26:52 PDT 2008

Without going into a lot of detail, *some* memory is allocated (for the
array structure, if you like) when you do the ReDim (some (4 bytes) has
already been allocated by the original Dim) but more will be allocated when
values are assigned to the strings because it is only at that point that the
system knows how much is needed.

What kind of processing are you doing for this to be significant?

--
Enjoy,
Tony

"cyberdude" <honchorlee@gmail.com> wrote in message
news:535d8cae-c8f2-421b-85dc-6011227a8ad4@e53g2000hsa.googlegroups.com...
> Hi,
>
> I defined A as an array in this way:
>
> Dim A() as string
>
> It is an array with unspecified array size.
>
> Somewhere in the programme, I define the array size like this:
>
> ReDim A(10)
>
> When I redim, does it mean some memory is immediately allocated for
> this array or does memory is allocated for this array ONLY when I
> define the elements as well, like, for example,
>
> ReDim A(10)
> A(1)="apple"
> A(2)="orange"
> ....
>
> ?
>
> Thanks.
>
> Mike
>


Re: Question about memory allocation by cyberdude

cyberdude
Sun Jul 13 02:23:25 PDT 2008

Hi Tony,

Thank you for the reply.

My process is a ReDim process which requires a lot of computer memory
as the array sizes are big. I have three arrays: array A, array B,
array C that hold strings. Array A and array B contain no null
elements. Array C contains a lot of null elements (that is, for
example, C(1)=3D""). I worried if a lot of null elements occupy a lot
of computer memory. This may slow down the computation as my computer
has very limited memory.

Mike

On 7=A4=EB13=A4=E9, =A4U=A4=C83=AE=C926=A4=C0, "Tony Jollans" <My forename =
at my surname dot com>
wrote:
> Without going into a lot of detail, *some* memory is allocated (for the
> array structure, if you like) when you do the ReDim (some (4 bytes) has
> already been allocated by the original Dim) but more will be allocated wh=
en
> values are assigned to the strings because it is only at that point that =
the
> system knows how much is needed.
>
> What kind of processing are you doing for this to be significant?
>
> --
> Enjoy,
> Tony
>
> "cyberdude" <honchor...@gmail.com> wrote in message
>
> news:535d8cae-c8f2-421b-85dc-6011227a8ad4@e53g2000hsa.googlegroups.com...
>
>
>
> > Hi,
>
> > I defined A as an array in this way:
>
> > Dim A() as string
>
> > It is an array with unspecified array size.
>
> > Somewhere in the programme, I define the array size like this:
>
> > ReDim A(10)
>
> > When I redim, does it mean some memory is immediately allocated for
> > this array or does memory is allocated for this array ONLY when I
> > define the elements as well, like, for example,
>
> > ReDim A(10)
> > A(1)=3D"apple"
> > A(2)=3D"orange"
> > ....
>
> > ?
>
> > Thanks.
>
> > Mike- =C1=F4=C2=C3=B3Q=A4=DE=A5=CE=A4=E5=A6r -
>
> - =C5=E3=A5=DC=B3Q=A4=DE=A5=CE=A4=E5=A6r -


Re: Question about memory allocation by Tony

Tony
Sun Jul 13 06:16:04 PDT 2008

If it's really significant (which, to be honest, I doubt) you could save a
little by assigning your empty strings to be vbNullString - but I think
that's what they'll be by default anyway unless you are explicitly assigning
empty strings to them.

--
Enjoy,
Tony

"cyberdude" <honchorlee@gmail.com> wrote in message
news:fcf4bbf7-f9d2-4b06-9317-08c816c4ab78@w7g2000hsa.googlegroups.com...
Hi Tony,

Thank you for the reply.

My process is a ReDim process which requires a lot of computer memory
as the array sizes are big. I have three arrays: array A, array B,
array C that hold strings. Array A and array B contain no null
elements. Array C contains a lot of null elements (that is, for
example, C(1)=""). I worried if a lot of null elements occupy a lot
of computer memory. This may slow down the computation as my computer
has very limited memory.

Mike

On 7¤ë13¤é, ¤U¤È3®É26¤À, "Tony Jollans" <My forename at my surname dot com>
wrote:
> Without going into a lot of detail, *some* memory is allocated (for the
> array structure, if you like) when you do the ReDim (some (4 bytes) has
> already been allocated by the original Dim) but more will be allocated
> when
> values are assigned to the strings because it is only at that point that
> the
> system knows how much is needed.
>
> What kind of processing are you doing for this to be significant?
>
> --
> Enjoy,
> Tony
>
> "cyberdude" <honchor...@gmail.com> wrote in message
>
> news:535d8cae-c8f2-421b-85dc-6011227a8ad4@e53g2000hsa.googlegroups.com...
>
>
>
> > Hi,
>
> > I defined A as an array in this way:
>
> > Dim A() as string
>
> > It is an array with unspecified array size.
>
> > Somewhere in the programme, I define the array size like this:
>
> > ReDim A(10)
>
> > When I redim, does it mean some memory is immediately allocated for
> > this array or does memory is allocated for this array ONLY when I
> > define the elements as well, like, for example,
>
> > ReDim A(10)
> > A(1)="apple"
> > A(2)="orange"
> > ....
>
> > ?
>
> > Thanks.
>
> > Mike- ÁôÂóQ¤Þ¥Î¤å¦r -
>
> - Åã¥Ü³Q¤Þ¥Î¤å¦r -


Re: Question about memory allocation by Karl

Karl
Tue Jul 15 13:52:44 PDT 2008

Tony Jollans wrote:
> If it's really significant (which, to be honest, I doubt) you could save a
> little by assigning your empty strings to be vbNullString - but I think
> that's what they'll be by default anyway unless you are explicitly assigning
> empty strings to them.

Yeah, new, unassigned Strings are, by definition.

This can be tested for with:

If StrPtr(X$) = 0 Then

In this particular case, I would hazard a guess that each empty/unassigned array
element is still occupying four bytes for the null pointer, though.
--
.NET: It's About Trust!
http://vfred.mvps.org