LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic multi-dimensional arrays

I am trying to read in a text file, store all the numbers in a dynamic multi-dimensional array and then write the numbers back to a binary file using fwrite. The text files are quite large(roughly 100k to 400k), I am trying to parse these files and write them in binary format to save space(about 50%). Multiple files will be combined into one binary file. The files are created consecutively so data integrity is very important. Is there such a thing as a dynamic multi-dimensional array? Or is there a better way to store the large masses of data?
0 Kudos
Message 1 of 3
(3,134 Views)
It is possible to build dynamic-, multi-dimensional arrays. One way to obtain them is as follows:

#include
static int **a;
static int i;

// Prepare array of pointers to sub-arrays
a = malloc (10 * sizeof (int));
for (i = 0; i < 10; i++) {
// Allocate inizialized memory for subarrays
*(a + i) = calloc (10 +i, sizeof (int));
}
a[0][0] = 1;
a[1][1] = 2;
a[9][9] = 10;

As you see in my example, this way you can even allocate a matrix with different-lenght rows. To you the task of managing this curious situation (if needed).

In order to save memory occupation when reading data files, you could consider using floats instead of doubles (4 bytes per cell instead of 8): memory saving is evident, if your data nature allows using them.

Hope this helps

Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(3,134 Views)
Another possible way is described here:
http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&8DE40999FF70BF208625683A000AE1CF&cat=40B44B36401CBACE06256874000FFBC5
Roberto


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 3
(3,134 Views)