How to create 4 dimensional array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jothivel
    New Member
    • Mar 2012
    • 12

    How to create 4 dimensional array

    Hi,
    I want to create 4 dimensional array, in that first three dimenstional are fixed size and the final index will be on 0 to N-numbers.
    For eg, double array[500][25][10][<NOT FIXED>].. So I cant create statically, because the index size are more. Also I have tried 4 dimenstional vector, but its giving 2 problem.
    (i) I am storing 4th dimenstion size is more than vector[0][0][0].max_size()
    (ii) Storing and Retrieving its more time in vector

    So Please let me know, if any other solution to store large array which is 3 index is FIXED and final one is not FIXED?
    Looking for answer from anyone..

    Thanks.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Read this: http://bytes.com/topic/c/insights/77...rrays-revealed

    What you describe is easily achieved by allocating your own array on the heap. There are examples in the linked article.

    Comment

    • jothivel
      New Member
      • Mar 2012
      • 12

      #3
      Hi,
      Thanks for your reply.
      Can you some example or link to create the own array on the heap?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        The example is in the article linked to in my post #2.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          On the whole if you have optimisation switched on storing and retrieving from a vector is the same as for an array.

          Comment

          • jothivel
            New Member
            • Mar 2012
            • 12

            #6
            Hi,
            Thanks for your answer.

            double array[500][25][10][<NOT FIXED>].
            I am achieving this using vector(vector(v ector(vector(do uble)))) dBuffer(....);
            As of now I am using vector[500][25][10][UnknownSize].
            UnknownSize will be decided on run time. It is working fine.
            But I am facing 2 problems.
            (i) I am storing 4th dimenstion size is more than
            vector[0][0][0].max_size()
            (ii) Storing and Retrieving its taking more time in vector for large index.

            Pls suggest any other method.

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              On my system, a vector<double> can hold 62 million doubles. You have more than that?

              Comment

              • jothivel
                New Member
                • Mar 2012
                • 12

                #8
                Hi, I could able to store in my double vector is = 536870911..
                But I need more than this index.

                Comment

                • weaknessforcats
                  Recognized Expert Expert
                  • Mar 2007
                  • 9214

                  #9
                  How many doubles do you need?

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Given that a double is 8 bytes (which it normally is) 536870911 of them take about 4GiB which if you are using a 32 bit operating system is likely to be the limit of the virtual memory space for your program.

                    If that is the case using an array wont help because the limit is the process memory space not what an individual array or vector can hold.

                    If you are using that much data use a file or a memory mapped file.

                    Comment

                    • jothivel
                      New Member
                      • Mar 2012
                      • 12

                      #11
                      Hi,
                      I need to create the double vector of
                      500*32*16*<un_k nownsize>..The final element i will push in runtime...

                      Comment

                      • jothivel
                        New Member
                        • Mar 2012
                        • 12

                        #12
                        Hi Banfa,

                        1) If i increase the virtual memory whether I can push much element.
                        2) More over I am not aware of memory mapped file. Please could you give some example to achieve.

                        Comment

                        • weaknessforcats
                          Recognized Expert Expert
                          • Mar 2007
                          • 9214

                          #13
                          Are you able to use database engine like Oracle? I'm starting to think that you will need to desing a database engine that more in it than one array.

                          Comment

                          • jothivel
                            New Member
                            • Mar 2012
                            • 12

                            #14
                            I can use database engine but it will take more time to insert data and retrieve back again.But my requirement is around I will take around 300MB of data in buffer then I will process and convert into double values, this size will be around 3.5GB, then I have to write into file. But if i use database everytime i have to insert then at the end i have to read back from database then I have to write into the file.

                            Comment

                            • weaknessforcats
                              Recognized Expert Expert
                              • Mar 2007
                              • 9214

                              #15
                              Except Oracle doesn't work that way - and it can handle terabyte tables.

                              As can, I believe Microsoft SQL Server.

                              I am starting to worry that you will send a ton of time writing a database handler rather than processing your doubles.

                              I have personally written a semented database from scratch to handle table than spanned six hard discs. It worked but I spent a lot of time getting it to work.

                              BTW: During this talk of a 4D array I need you to be clear that there are only 1D arrays in both C and C++. The "dimensions " are just a way of getting the compiler to do your pointer arithmetic.

                              Comment

                              Working...