max integer array size with 512mb ram

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nk28
    New Member
    • Jan 2010
    • 26

    max integer array size with 512mb ram

    my question is that i have 512 mb ram .What is the max integer array size that i can declare in c.
    I recently experimented with different values and found that while i am able to create large values of array size the moment i use them i get "segmentati on fault" error.

    All i know is that the answer is related to the actual stack size in my computer..


    can someone help me???
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    There is no hard and fast answer for this. It changes dynamically.

    Comment

    • johny10151981
      Top Contributor
      • Jan 2010
      • 1059

      #3
      (I am writing this but not that confident about it. Never Read it any where just worked out)
      say your compiler is x bit compiler.
      Now try

      MaxArraySize=po w(2,x-1)-1
      (I Believe it will work best for char type.)

      MaxArraySize=(p ow(2,x-1))/(sizeof specific_variab le_type)-1
      (This will work for diff variable type)
      Let me know if I am wrong.

      Regards,
      Johny

      Comment

      • mac11
        Contributor
        • Apr 2007
        • 256

        #4
        The amount of memory you can allocate isn't going to be something you can easily compute unless your operating system has a very specific and deterministic memory model.

        Most OS use virtual memory and also allow over committing or memory requests in order to make life easy and let things run. For instance if you have 512MB ram your OS may let you ask for 1GB ram with a series of malloc or new requests.

        If you want to understand more a search for memory management or over commit or some such may be helpful.

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Also many OSes have memory swap to the harddisk. So theoretically you could have an array that is the maximum size of both your memory and hard disk, but that would never fly.

          Comment

          • nk28
            New Member
            • Jan 2010
            • 26

            #6
            Thanks a lot everybody.....A ctually i am going to post something i was told by someone but still i would like to know if its correct.
            The max array size depends on 2 things...OS and Ram size....There's a fixed stack size in our memory for each os and we can increase the size from the heap to it....So the max size of array is actually fixed for each computer but can be changed to infinity......

            Comment

            • whodgson
              Contributor
              • Jan 2007
              • 542

              #7
              No thats nonsense. i think you would be better off doing some realistic C++ programming instead of pursuing these these way out theories.

              Comment

              • nk28
                New Member
                • Jan 2010
                • 26

                #8
                uhmm...thanks for the reply but i need to find the max array size for the programming so......i need to find the answer......

                Comment

                • mac11
                  Contributor
                  • Apr 2007
                  • 256

                  #9
                  What are you actually trying to program?

                  Maybe we can help you better achieve your goal if we know what your desired end result is, and all this talk of maximum possible array size might not be pertinent to whatever task you're trying to undertake.

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    There may be a platform dependant answer to your question "what is the maximum array size" but it would be just that, platform dependant. Since you have not specified the platform (giving the RAM size is not a specification of the platform, at the very least you would need to add processor and operating system and toolchain) the question remains unanswerable.

                    Comment

                    • alexis4
                      New Member
                      • Dec 2009
                      • 113

                      #11
                      Furthermore your array could be allocated, static or automatic. So in every case, you need first of all to make sure your compiler has allocated enough space by its own settings for the stack or the heap, depending on how this array is declared.
                      But anyway answers could be theoretical on some situations. Because if you have a 512MB RAM but your running processes are using 100MB, then the maximum size would be (512-100)/sizeof(int).

                      Comment

                      • nk28
                        New Member
                        • Jan 2010
                        • 26

                        #12
                        okay first of all i have found that i can easily make an array size of 200000 so as to make people realise that the answer is not as short as range of int etc....

                        My OS is windows Xp with 2.6 Ghz intel proccesor.

                        I am actually trying to find the complexities of various algorithms and for it i need to go as large as possible....Now one option is simply declaring dynamically and putting numbers randomly...i know about it.....

                        I only wanted to ask if someone knew how much numbers can i put theoretically in a fixed static integer array......

                        Comment

                        • RedSon
                          Recognized Expert Expert
                          • Jan 2007
                          • 4980

                          #13
                          Originally posted by nk28
                          I am actually trying to find the complexities of various algorithms and for it i need to go as large as possible...
                          If you want to find the complexity of an algorithm why don't you use "infinity" instead of trying to figure out what your system can do.

                          However, using infinity brings you into the realm of pure mathematics and computation complexity theory and away from the application of those two domains.

                          I suggest you do a bit of reading on a topic like "Big O notation"

                          (see: http://en.wikipedia.org/wiki/Big_O_notation)

                          Comment

                          • Banfa
                            Recognized Expert Expert
                            • Feb 2006
                            • 9067

                            #14
                            Well in theory then you should be able to have any integer array of approximately

                            2 Gigabytes / sizeof(int) = 536,870,912

                            You wont be able to attain this actual number as some memory will be used for other program variables, heap and stack. If you reserve a megabyte for that which is plenty if you are careful then you get 536,608,768.

                            The physical memory size is on no consequence as Windows uses a page file to supplement physical memory but you would have to make sure your page file was configured to expand if required (up to 2-3 gigbytes should do it).

                            That number would be the largest number that you could use whether the array was static, on the stack or on the heap. In Windows both the stack and heap of a program expand as required but the stack, heap and static data all have to fit into the virtual address space that reserves 2 gigabytes of virtual address space for user data (as opposed to system data which also has 2 gigabytes of virtual address space reserved).

                            Comment

                            • RedSon
                              Recognized Expert Expert
                              • Jan 2007
                              • 4980

                              #15
                              Yes that is all true, however as soon as you move to a different platform/compiler/computer/hardware/anything your results become invalid.

                              If you want to know the true complexity of an algorithm you need to express it mathematically using some kind of notation.

                              Comment

                              Working...