dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Limitations of ReDim statement

Hybrid View

  1. #1
    Join Date
    Nov 2001
    Location
    USA, Florida
    Posts
    60

    Limitations of ReDim statement

    Hi all,

    I am attempting to redim an array of doubles,
    if I use ReDim dArray(2000000) (2 million records)- gives out 'Out of memory' error,
    while ReDim dArray(1000000) (1 million records) - works fine.

    Is there a formal limitation for rediming an array? Is it upper index? Or physical properties of the current machine?

    Thank you

    Biasha

  2. #2
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    My understanding is, the only limit is the physical memory available to your application (total RAM minus whatever application, driver, etc, that are running).

    Another consideration is the record length. You may have a record length of 512 byte (example), so you will be using "Ubound(dArray) * 512" memory resources.

    Then, I can't recall where I read this -- something like:
    If you declare an array of variable length string or variant, behind the scene (hidden from VB programmers), VB is maintaining another array as pointer or flag or something that will determine the actual length of string value or the actual data type value of a variant or both. So it will take so much resources.
    Last edited by aio; September 17th, 2002 at 08:08 PM.
    Marketing our skills - please participate in the survey and share your insights
    -

  3. #3
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Actually, it is not "physical memory limitation", it is "Visual Basic Array limitations", each variable type has a length, a double use 8 Bytes and an integer use 2 Bytes. I don't know the size limitation, but a 2 000 000 double array will be, in size:

    2 000 000 * 8 + 24 (16 000 048 Bytes) (~16 MB)

    Count it, and see that 1 000 000 is a lot LESS since it is an array, but if you change it to integer, the number 8 in the formulas can be changed to 2; it is four times smaller.

    But, the size allowed by Visual Basic might be dependant of the total OS physical free memory (I don't know about that), but it is sure have a limitation, if you have a so big array, think to use a database or any external storing places

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  4. #4
    Join Date
    Nov 2001
    Location
    USA, Florida
    Posts
    60
    Thank you all for the reply, to be more speceific:

    ReDim darray(0 To 1, 0 To 13, 0 To 1000000) - works
    ReDim darray(0 To 1, 0 To 13, 0 To 2000000) - does't work...

    Can you confirm?

    Thank you,

    Biasha

  5. #5
    Join Date
    Aug 2001
    Posts
    1,447
    confirm what?

    either it works for you or it doesn't. how can we confirm what works on YOUR system?

    on my system, even the first statement causes a hang-up (although as on yours, it doesn't cause a compile-level error message, which the 2nd one does)
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  6. #6
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054
    Both didn't work for me.
    Marketing our skills - please participate in the survey and share your insights
    -

  7. #7
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Hi Biasha,

    I think it is just memory limitation.

    -Cool Bizs

  8. #8
    Join Date
    Nov 2001
    Location
    USA, Florida
    Posts
    60
    I guess, the limit is a combination of factors, first obvious is physical memory, but if there is enough, there is a limit posted by the internal process of allocating memory for array. Since on my machine I do not use up all of th physical memory for the second call (see above), I am presented with the structural limit - this is the limit I was asking about.

    Thank you

    Biasha

  9. #9
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Also remember that each app is only given 4GB of memory space (virtually). 2GB is used by the OS while the rest is for the APP. But, that does not mean you have 2GB to play with. You only have part of the 2GB (I can't remember what are the figures) called HEAP that is used when you do dynamic memory allocation (such as arrays). Once this is filled up, then you will also get OUT OF MEMORY error.

    -Cool Bizs

  10. #10
    Join Date
    Jun 2002
    Location
    Lyman ME - USA | Oneonta NY - USA
    Posts
    399
    ok well i see it as this...if you can do an array of 1000000 and you are trying to goto 2000000 then just do it this way...
    take 1000000 and make the 1000000 element point to the first in a new array...somewhat like a linked list...shouldn't be bad...what you could do is just hold the new array that holds doubles in the first array...and so on and so forth...you can figure out the rest of the programming...
    let me know if VB wont let you do this...if that is the case then i believe it's time to learn a real language
    I know that i can do it in Java and C++ will let you but the only limitations i can see are physical memory...You have an aloted amount...by both the RAM and VM...make sure you aren't hitting those limits...

    hope it helps

    - nc
    Last edited by booogt; September 23rd, 2002 at 08:03 PM.
    "In a world without walls and barriers, what need is there for windows and gates!" - a mac ad
    "What was the best thing before sliced bread and when did sliced bread go out of existence?" - me
    "Software is like sex, it's better when it's free." - Linus Torvalds <- gotten from Andreas Masur


    Live Penguine! - Tux the linux mascot
    Vivez le penguine!, ¡Viva en penguine!, Lang lebe der Pinguin!, Viva no penguine!, Viva sul penguine!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)