Results 1 to 9 of 9

Thread: Array

  1. #1

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Angry

    How can I see how many bytes an array need?
    Is it like this:
    Dim MyArr(999,999,1) as string
    In the first dimension are there 1000 places(0->999), in the second also 1000, and in the third are there 2 places, so: 1000*1000*2=2000000 bytes =2MB?

    Am I right? Tell me

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  2. #2
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196
    Thats basically 2 million *elements* in your array. Then you have to multiply that by the space that each string takes up. Since it is variable length strings that you are storing, this amount of space also varies...

    i'm not sure of the exact specs, but basically if all your strings averaged, say, 50 bytes (characters), then you get 2Mb * 50 = 100Mb

    whichever way its alot of space...

    hope this helps a bit..


  3. #3

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Wink 100 MB RAM?

    Thank you, but for easy working, does the user need 100MB RAM?

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    each variable length string is 10 bytes + length of string * 2
    each dimension in an array needs 2 bytes for descriptor, that makes the length:
    10*1000*1000*2+2+2+2+2X = 20 000 000 + 2X
    that is that it automatically takes up 20MB RAM + 2*the amount of space all the strings takes up
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196
    WP,

    may i ask what sort of application requires 2 million strings? just curious...

  6. #6

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Talking 2X ?

    Oh, its just an example, i wanted to know how i can count the needed bytes (i'm not using this big array)

    But Kedaman,
    + 2*the amount of space all the strings takes up
    What exactly do you mean, its 20MB RAM + ?

    thanks

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

  7. #7
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    Re: 2X ?

    Originally posted by WP
    But Kedaman,
    + 2*the amount of space all the strings takes up
    What exactly do you mean, its 20MB RAM + ?
    [/B]
    What he means is that, say you have a string that contains:

    "Hi there WP", that takes up 11 bytes (since 11 characters), then the length of the string is 11, and according to kedaman it takes up 10 + 2*11 bytes.

    so if you have 2 million strings each of length 11, then "the amount of space all the strings takes up" will be 2 million times 11.

    so the complete grand total figure for the amount of memory it would take up would be:

    20MB + 2 * ( 2,000,000 * 11) = 64MB RAM total.


  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Thats correct funky, strings are unicode by default in vb, that means each character takes up 2 bytes. You could reduce the amount of space by converting from unicode into a byte array for instance:
    Dim a() as byte
    A=strconv("THIS TAKES UP 44 BYTES",vbfromunicode)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Hyperactive Member WP's Avatar
    Join Date
    Aug 2000
    Location
    Belgium
    Posts
    278

    Wink Thanks

    Thanks a lot, all of you. Now I can avoid the "out of memory" error cause I can calculate the needed RAM.

    WP

    Visual Basic 6.0 EE SP5 / .Net
    Windows XP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width