Re: Size of arrary
From: Bob (anonymous_at_discussions.microsoft.com.invalid)
Date: 05/17/04
- Next message: Bob: "Re: viewing newsgroups with outlook express"
- Previous message: Krzysztof Malinowski: "Persistance on ComboBox"
- In reply to: MikeD: "Re: Size of arrary"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 17 May 2004 13:24:46 -0700
As always, thanks very much for all the wonderful information Mike.
Morethan anything, I was just curious. I thought there may be a magic api
or something that would give you the information. I guess, not. I can put
a loop, and count the size of individual elements.
By the way, you brought up another point, and that is, is there a way of
know how much memory my application really takes, other than looking at task
manager?
Bob
"MikeD" <nobody@nowhere.edu> wrote in message
news:%23Igu065OEHA.1960@TK2MSFTNGP10.phx.gbl...
>
> "bob" <anonymous@discussions.microsoft.com> wrote in message
> news:97F68FC0-8C49-438E-ABED-153FDEAA48FE@microsoft.com...
> > Hello all:
> >
> > I have two arrays, one is of type variable length string, and the other
> one of type variant. I was wondering in VB 6.0, if there is a way of
> knowing how much memory each array takes? I guess, one way would be to
use
> a loop, and count the number of characters in each item of the array, and
> then sum them up. However, I was hoping that there may be a cleaner way
to
> do it, or even may be an api function.
>
>
> Arrays, in and of themselves, require a specific amount of memory. Each
> data type also requires a specific amount of memory. These memory
> requirements are documented. See the following:
>
> http://msdn.microsoft.com/library/en-us/vbenlr98/html/vagrpDataType.asp
>
> For the string array, you'll need to loop through all the elements because
> you do indeed need to count the length of each string assigned to each
array
> element. You need to add 10 bytes for each string (from the above page, a
> variable-length string requires 10 bytes + length of string).
Additionally,
> the array itself requires 20 bytes plus 4 bytes per dimension. Therefore,
> code to calculate the memory usage would be:
>
> (air code)
> Dim lMem As Long
> Dim Index As Long
> For Index = LBound(MyStringArray) To UBound(MyStringArray)
> lMem = lMem + Len(MyStringArray(Index)) + 10
> Next
> lMem = lMem + 20 + (4 * lNumDimensions)
>
> Now, see if you can figure it out yourself for the array of variants.
It's
> going to be a little more difficult; one reason being that you'll need to
> determine the subtype of the data assigned to each element (unless they're
> all the same, but in that case, why are you using a variant?). From the
> data type summary page, a variant storing any numeric value (as
documented,
> up to a Double) requires 16 bytes. A variant storing a string requires 22
> bytes + length of string. From that point, you just need to add the
> "regular" overhead of the array (20 bytes + 4 bytes per dimension).
>
> Just curious, but why is this important? Or are you just wondering? If
> you're trying to figure out minimum memory requirements for your entire
app,
> counting up *every* usage of arrays, variables, constants, object
> references, UDTs, etc., (plus figuring in scope), would be a nearly
> impossible task And quite frankly, it wouldn't mean a whole lot. Apps
(any
> app, VB or not) *rarely* use up available RAM. What they *may* use up are
> system resources, stack space, etc. (IOW, limits imposed by Windows, and
> these vary from one version of Windows to another).
>
> Mike
>
>
>
- Next message: Bob: "Re: viewing newsgroups with outlook express"
- Previous message: Krzysztof Malinowski: "Persistance on ComboBox"
- In reply to: MikeD: "Re: Size of arrary"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|