473,509 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create 4 dimensional array

12 New Member
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.
Apr 24 '13 #1
19 9495
weaknessforcats
9,208 Recognized Expert Moderator Expert
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.
Apr 24 '13 #2
jothivel
12 New Member
Hi,
Thanks for your reply.
Can you some example or link to create the own array on the heap?
Apr 25 '13 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
The example is in the article linked to in my post #2.
Apr 25 '13 #4
Banfa
9,065 Recognized Expert Moderator Expert
On the whole if you have optimisation switched on storing and retrieving from a vector is the same as for an array.
Apr 25 '13 #5
jothivel
12 New Member
Hi,
Thanks for your answer.

double array[500][25][10][<NOT FIXED>].
I am achieving this using vector(vector(vector(vector(double)))) 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.
Apr 25 '13 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
On my system, a vector<double> can hold 62 million doubles. You have more than that?
Apr 25 '13 #7
jothivel
12 New Member
Hi, I could able to store in my double vector is = 536870911..
But I need more than this index.
Apr 26 '13 #8
weaknessforcats
9,208 Recognized Expert Moderator Expert
How many doubles do you need?
Apr 26 '13 #9
Banfa
9,065 Recognized Expert Moderator Expert
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.
Apr 26 '13 #10
jothivel
12 New Member
Hi,
I need to create the double vector of
500*32*16*<un_knownsize>..The final element i will push in runtime...
Apr 26 '13 #11
jothivel
12 New Member
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.
Apr 26 '13 #12
weaknessforcats
9,208 Recognized Expert Moderator Expert
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.
Apr 26 '13 #13
jothivel
12 New Member
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.
Apr 27 '13 #14
weaknessforcats
9,208 Recognized Expert Moderator Expert
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.
Apr 27 '13 #15
Banfa
9,065 Recognized Expert Moderator Expert
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.
Apr 29 '13 #16
weaknessforcats
9,208 Recognized Expert Moderator Expert
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.
Apr 29 '13 #17
Sherin
77 New Member
Try This Code

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <stdio.h> 
  3. int main() 
  4.  
  5.     int i, j, k, l, size; 
  6.  
  7.     int a[2][2][2][2]; 
  8.  
  9.     size = 2; 
  10.  
  11.     a[0][0][0][0] = 5; 
  12.     a[0][0][0][1] = 3; 
  13.     a[0][0][1][0] = 5; 
  14.     a[0][0][1][1] = 3; 
  15.     a[0][1][0][0] = 6; 
  16.     a[0][1][0][1] = 7; 
  17.     a[0][1][1][0] = 6; 
  18.     a[0][1][1][1] = 7; 
  19.     a[1][0][0][0] = 8; 
  20.     a[1][0][0][1] = 9; 
  21.     a[1][0][1][0] = 8; 
  22.     a[1][0][1][1] = 9; 
  23.     a[1][1][0][0] = 9; 
  24.     a[1][1][0][1] = 7; 
  25.     a[1][1][1][0] = 9; 
  26.     a[1][1][1][1] = 7; 
  27.  
  28.     for (i = 0; i < size; i++) { 
  29.         for (j = 0; j < size; j++) { 
  30.             for (k = 0; k < size; k++) { 
  31.                 for (l = 0; l < size; l++) { 
  32.                     printf("Value of a[%d][%d][%d][%d] :- %d ", 
  33.                                 i, j, k, l, a[i][j][k][l]); 
  34.                     printf("\n"); 
  35.                 } 
  36.             } 
  37.         } 
  38.     } 
  39.     return 0; 
Jan 20 '21 #18
Banfa
9,065 Recognized Expert Moderator Expert
@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.
Jan 25 '21 #19
SwissProgrammer
220 New Member
@weaknessforcats

"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 .
May 18 '21 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4065
by: Nick | last post by:
Loop to create an array from a dynamic form. I'm having trouble with an application, and I'll try to explain it as clearly as possible: 1. I have a form with two fields, say Apples and...
22
2695
by: nobody | last post by:
hello everybody, is there a way of creating an array with help of a function that would accept the name of this array as a parameter and then create global Array type variable of that name? so...
7
1458
by: Piotre Ugrumov | last post by:
I have tried to write the class Student(Studente), Teacher(Docente). This classes derive from the class Person. In a class university(facoltà). I have tried to create an array of Student and an...
6
2355
by: billy | last post by:
I've got a set of subclasses that each derive from a common base class. What I'd like to do is create a global array of the class types (or, class names) that a manager class can walk through in...
1
1628
by: SAN CAZIANO | last post by:
is there a function that get the name of the first input field of the current form ? in my example below I want create an array of form field name and in the onsubmit assign all element's name to...
3
32475
by: jhs | last post by:
Hello, I developping a .NET windows form application an need some help to create an array of System.Windows.Forms.Label in order to be able to manage all of them using index. I'm trying to do...
2
7971
by: Wendell Wilkie | last post by:
I am working with a 3rd party unmanaged dll, and I need to pass an array of char* as an argument. I can used fixed to get a single char* as follows: char buf = new char; fixed (char* p = buf)...
2
1643
by: Big Charles | last post by:
Hello, I would like to create an array-class to be able to call like: Dim oMyCar as New MyCar ' After initializing oMyCar, the object has to be like: oMyCar(0).Brand...
11
4617
by: memeticvirus | last post by:
I have an array cli::array<float, 2and I would like to access a subset of it's values by compiling an array of pointers. But, it's not possible to create an array of type...
3
4831
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.