Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how big array size does a visual c++ program allow ?

how big array size does a visual c++ program allow ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structurestutorialquestion
15 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrby123
    wrote on last edited by
    #1

    I have a program which has a total of array size of 94000 float(31 arrays). When I change 9 of the arrays (73737 size) into double, my program seems not working. Is the total array size too big ? How to fix the problem ? Thanks for any help.

    B J S 3 Replies Last reply
    0
    • M mrby123

      I have a program which has a total of array size of 94000 float(31 arrays). When I change 9 of the arrays (73737 size) into double, my program seems not working. Is the total array size too big ? How to fix the problem ? Thanks for any help.

      B Offline
      B Offline
      basementman
      wrote on last edited by
      #2

      Typically, when you need an array of more than a few hundred elements, it is best to allocate the array on the heap. This allows you to create arrays bounded only by memory (or 2GB if on w32).  onwards and upwards...

      M 2 Replies Last reply
      0
      • B basementman

        Typically, when you need an array of more than a few hundred elements, it is best to allocate the array on the heap. This allows you to create arrays bounded only by memory (or 2GB if on w32).  onwards and upwards...

        M Offline
        M Offline
        mrby123
        wrote on last edited by
        #3

        Thanks for the advice. You mean I should using pointers ? I am a programer from Fortran/Java. I have not got used to pointers. Give me detailed or further advice please.

        N 1 Reply Last reply
        0
        • M mrby123

          Thanks for the advice. You mean I should using pointers ? I am a programer from Fortran/Java. I have not got used to pointers. Give me detailed or further advice please.

          N Offline
          N Offline
          Nacho Chip
          wrote on last edited by
          #4

          For the array, in order to use the heap memory, you can allocate your array like this float* floatArray = NULL; floatArray = new float[100]; and when you finish using your array, you can delete [] floatArray; floatArray = NULL; I wish it help! Nacho

          M 1 Reply Last reply
          0
          • B basementman

            Typically, when you need an array of more than a few hundred elements, it is best to allocate the array on the heap. This allows you to create arrays bounded only by memory (or 2GB if on w32).  onwards and upwards...

            M Offline
            M Offline
            mrby123
            wrote on last edited by
            #5

            Thanks for the advice. You mean I should using pointers ? I am a programer from Fortran/Java. I have not got used to pointers. Give me detailed or further advice please. I particularly use six big arrays a[8200],b[8200],c[8200] Ideally I need to expand my program to a[16400],b[16400],c[16400]. However, I tried these expansion, the program stopped to work. message says: memery problem. -- modified at 15:27 Monday 24th April, 2006

            M 1 Reply Last reply
            0
            • M mrby123

              Thanks for the advice. You mean I should using pointers ? I am a programer from Fortran/Java. I have not got used to pointers. Give me detailed or further advice please. I particularly use six big arrays a[8200],b[8200],c[8200] Ideally I need to expand my program to a[16400],b[16400],c[16400]. However, I tried these expansion, the program stopped to work. message says: memery problem. -- modified at 15:27 Monday 24th April, 2006

              M Offline
              M Offline
              Maximilien
              wrote on last edited by
              #6

              using pointers will not fix all your problems but will help you deal with memory problems. normally, when allocating memory on the heap ( with new ) you will have a immediate result telling you that the allocation worked or not.


              Maximilien Lincourt Your Head A Splode - Strong Bad

              M 1 Reply Last reply
              0
              • N Nacho Chip

                For the array, in order to use the heap memory, you can allocate your array like this float* floatArray = NULL; floatArray = new float[100]; and when you finish using your array, you can delete [] floatArray; floatArray = NULL; I wish it help! Nacho

                M Offline
                M Offline
                mrby123
                wrote on last edited by
                #7

                Thanks Nacho. I have implemented your code suggestion.

                1 Reply Last reply
                0
                • M Maximilien

                  using pointers will not fix all your problems but will help you deal with memory problems. normally, when allocating memory on the heap ( with new ) you will have a immediate result telling you that the allocation worked or not.


                  Maximilien Lincourt Your Head A Splode - Strong Bad

                  M Offline
                  M Offline
                  mrby123
                  wrote on last edited by
                  #8

                  Thanks I need to expand the size of the arrays. How can I do this ? Ideally I should also use "double" instead of "float" to improve the accuracy of the calculations. However, I tried I can not do it now due to the memery limitations. Please help me to get a way to deal with this problem Thanks

                  1 Reply Last reply
                  0
                  • M mrby123

                    I have a program which has a total of array size of 94000 float(31 arrays). When I change 9 of the arrays (73737 size) into double, my program seems not working. Is the total array size too big ? How to fix the problem ? Thanks for any help.

                    J Offline
                    J Offline
                    Joe Woodbury
                    wrote on last edited by
                    #9

                    [Message Deleted]

                    V M R 3 Replies Last reply
                    0
                    • J Joe Woodbury

                      [Message Deleted]

                      V Offline
                      V Offline
                      venadder
                      wrote on last edited by
                      #10

                      i agree, Use heap instead of stack. If you ar ein C++ now, then you won't be really be able to avoid pointers and dynamic allocation.

                      1 Reply Last reply
                      0
                      • J Joe Woodbury

                        [Message Deleted]

                        M Offline
                        M Offline
                        mrby123
                        wrote on last edited by
                        #11

                        would you please give me some code example segments for using GlobalAlloc()? Thanks

                        D 1 Reply Last reply
                        0
                        • M mrby123

                          would you please give me some code example segments for using GlobalAlloc()? Thanks

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #12

                          mrby123 wrote:

                          would you please give me some code example segments for using GlobalAlloc()?

                          There's no reason to use GlocalAlloc(), unless you are maintaining old 16-bit code. Use new and delete instead.


                          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                          "We will be known forever by the tracks we leave." - Native American Proverb

                          1 Reply Last reply
                          0
                          • M mrby123

                            I have a program which has a total of array size of 94000 float(31 arrays). When I change 9 of the arrays (73737 size) into double, my program seems not working. Is the total array size too big ? How to fix the problem ? Thanks for any help.

                            S Offline
                            S Offline
                            Stephen Hewitt
                            wrote on last edited by
                            #13

                            Using new and delete [] or GlobalAlloc will work but it is operating at an unnecessarily low level. Standard C++ has a container called a vector which will suit your needs and has many advantages including the fact that it automatically frees memory saving you from the burden of remembering to call delete []. To use it first include its header file like this: #include <vector> Now you can whip up a vector of floats like this: std::vector<float> YourVectorOfFloats Now you can use this as before but you don't need to call delete [] and it has lots of member functions that you can use. For example, you want to expand it? No worries: YourVectorOfFloats.resize(400); Unless he has highly specialized needs there is no good reason for a C++ programmer to use new and delete [] or Win32 APIs such as GlobalAlloc to make dynamic arrays - In general it is a mistake to do so. Steve

                            M 1 Reply Last reply
                            0
                            • J Joe Woodbury

                              [Message Deleted]

                              R Offline
                              R Offline
                              Rilhas
                              wrote on last edited by
                              #14

                              I would strongly sugest you not to use GlobalAlloc(). Why limit your code to Windows if you don't really need to? Standard ANSI should be fine for your problem. I assume, of course, that you are programming for Win32. If this is not the case then my comments don't apply. But if you avoid GlobalAlloc() you can easilly port to LINUX, which is very similar to Win32 but where GlobalAlloc() doesn't exist. The first thing you need to do is estimate how much memory you are demanding from the system. From your figures I assume the largest is 3 arrays of doubles with 16400 entries each. Since each double is 8 bytes on most platforms, this results in a total of 393600 bytes of RAM. That's peanuts by today's standards... I assume your computer is equipped with 16MB of RAM or more, so memory outage is surelly not the problem. I have 512 MB, and I once needed 1.3 GB for a simulation, and the virtual memory manager tolerated it just fine. So I'm sure memory outage is not a problem. There are no real limits on array sizes except those you declare on the stack. Stack is the only real limited resource. It is the space where you declare local variables, and the space the compiler uses to remember where to return to after a function call and where it places the parameters that you pass to functions. If you are not used to pointers then I would suggest you use a little class to wrap the pointer code. I will paste an example below. This will hide the complexities of allocation and will tolerate bad pointer coding practices. template class Array { protected: T* itsBuffer; long itsBufferCount; void Crash(void) { char* p=0; *p=0; } public: Array(long count) { itsBuffer=new T[count]; itsBufferCount=count; if (!itsBuffer) Crash(); } Array(Array& arr); // dummy ~Array() { if (itsBuffer) delete [] itsBuffer; } long GetCount(void) { return itsBufferCount; } T* Get(long index_0_based=0) { if (index_0_based<0) Crash(); if (index_0_based>=itsBufferCount) Crash(); return itsBuffer+index_0_based; } T& operator[](long index_0_based) { return *Get(index_0_based); } }; long main_2(Array arr) { return arr.GetCount(); } long main_3(Array& arr) { return arr.GetCount(); } void main(void) { long i; long arr_size=16400; Array arr_a(arr_size); Array arr_b(arr_size); Array arr_c(arr_size); #ifdef _DEBUG // slow protected implementation to detect software errors Array& a

                              1 Reply Last reply
                              0
                              • S Stephen Hewitt

                                Using new and delete [] or GlobalAlloc will work but it is operating at an unnecessarily low level. Standard C++ has a container called a vector which will suit your needs and has many advantages including the fact that it automatically frees memory saving you from the burden of remembering to call delete []. To use it first include its header file like this: #include <vector> Now you can whip up a vector of floats like this: std::vector<float> YourVectorOfFloats Now you can use this as before but you don't need to call delete [] and it has lots of member functions that you can use. For example, you want to expand it? No worries: YourVectorOfFloats.resize(400); Unless he has highly specialized needs there is no good reason for a C++ programmer to use new and delete [] or Win32 APIs such as GlobalAlloc to make dynamic arrays - In general it is a mistake to do so. Steve

                                M Offline
                                M Offline
                                mrby123
                                wrote on last edited by
                                #15

                                Thanks Steve, I will implement it.

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups