How to create 4 dimensional array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #16
    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.
    I have to admit to be slightly surprised that you didn't say this in your first post.

    Are you sure a database is required? It sounds like the process is
    1. Read Data
    2. Process Data
    3. Write File

    If (BIG IF) the data can be processed linearly and written straight to file then you don't actually need to do any more than store the original 300MByte of data which isn't so bad.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #17
      Are you sure a database is required:
      You may be right, but hard to say since the number of doubles required is unknown. That raises the possibility the data will exceed the maximum file size and that would result in a segmented data structure. The result is spending time on things other than processing the data.

      Comment

      • Sherin
        New Member
        • Jan 2020
        • 77

        #18
        Try This Code

        Code:
        #include <stdio.h> 
        int main() 
        { 
        	
        	int i, j, k, l, size; 
        
        	int a[2][2][2][2]; 
        
        	size = 2; 
        
        	a[0][0][0][0] = 5; 
        	a[0][0][0][1] = 3; 
        	a[0][0][1][0] = 5; 
        	a[0][0][1][1] = 3; 
        	a[0][1][0][0] = 6; 
        	a[0][1][0][1] = 7; 
        	a[0][1][1][0] = 6; 
        	a[0][1][1][1] = 7; 
        	a[1][0][0][0] = 8; 
        	a[1][0][0][1] = 9; 
        	a[1][0][1][0] = 8; 
        	a[1][0][1][1] = 9; 
        	a[1][1][0][0] = 9; 
        	a[1][1][0][1] = 7; 
        	a[1][1][1][0] = 9; 
        	a[1][1][1][1] = 7; 
        
        	for (i = 0; i < size; i++) { 
        		for (j = 0; j < size; j++) { 
        			for (k = 0; k < size; k++) { 
        				for (l = 0; l < size; l++) { 
        					printf("Value of a[%d][%d][%d][%d] :- %d ", 
        								i, j, k, l, a[i][j][k][l]); 
        					printf("\n"); 
        				} 
        			} 
        		} 
        	} 
        	return 0; 
        }

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #19
          @Sherin, I don't think you have appreciated the problem that this thread is about which is not having a 4 dimensional array but rather processing and extremely large volume of data. Because of that the rather trivial example code posted is of little to no use in solving the actual problem.

          Comment

          • SwissProgrammer
            New Member
            • Jun 2020
            • 220

            #20
            @weaknessforcat s

            "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."

            That is interesting. Instead of looking at it as multi-dimensional, maybe I should look at it as single dimensional with a potential for dimensions inside of that first dimension like a tree. Start with one dimension and get that to work, then work on one more dimension at a time getting each of those to work before going on to more of the tree.

            Thanks: This is an easier way to look at it (for me).

            I am working on (still at it) a shortest path algorithm (with variably changing constraints) that can handle a 1,000+ by 1,000+ grid. I was considering multi-dimensional vectors and trying to get that to work. I think that I shall go back to designing based upon a single dimension vector now; and potentially use other dimensions for variable conditions within that first dimension's elements.

            Maybe as a single dimension like this?
            vector <std::wstring > Grid_X_Y (1000000);
            to start. Then I can concatenate the elements as data is added or changed.

            Or maybe with multiple dimensions like this?
            vector <std::wstring > Grid_X_Y (1000000,10);
            to start. Then I can add up to 10 values per each of the first dimension's elements. This might make it easier to choose a value later rather than having to parse each wstring as in the single dimension example.

            Maybe this process might help the OP.

            Thank you weaknessforcats .

            Thank you bytes.com .

            Glory to God .

            Comment

            Working...