Re: Size of arrary

From: Bob (anonymous_at_discussions.microsoft.com.invalid)
Date: 05/17/04


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
>
>
>



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: Split Function Creates Error 13 Type Mismatch
    ... A Variant can hold a string and an array of string. ... Dim vAs Variant ... As it is, was Variant accept an array of string returned by Array, but not by Split. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Grouping shapes in Word
    ... The reason that it expects a Variant array as opposed to a String array is that ... a Variant can hold data of any type. ... Variant array of Shape names (string) or a Variant array of shape index numbers ... Dim avarShape() As Variant ...
    (microsoft.public.office.developer.vba)
  • Re: Sorting a variant array
    ... Dim tempList As Variant ... Dim testerList() As String ... Function sortTesters(rangeName As String) ... column range--but even that ends up as a x-rows by 1 column array. ...
    (microsoft.public.excel.programming)
  • Re: Substring
    ... A common scenario is in fact taking an initial string and chopping it into smaller pieces. ... It's more efficient to do this using a single common source array and just maintaining indices into the array, both in terms of memory usage and in terms of speed. ... Worrying about the shared array is a premature optimization at best, and ignores an important "common case" optimization at worst. ...
    (comp.lang.java.programmer)

Loading