Sunday, December 5, 2010

Dynamic allocation of multi-dimentional array

I've spent the late morning fleshing out my .plx file loader. It's mostly gruntwork right now making printf() lines for each interesting bit of info in the headers. At some point I'll get to the actual data itself, and I'm thinking of the best way to do this.

I know for a fact that there won't be more than 128 channels of information, and each channel will have various header data of its own. So, I could make a big array of size 128 of structures, or I could dynamically allocate the array based on the number of channels actually in the file.

Then, for each channel header it will have waveform data (32 points of digitized analog data) - again I won't know how many of these waveforms will exist until I read the channel header, so now I have an opportunity to dynamically allocate a multi-dimensional array of N x 32. I found this info:

http://c-faq.com/~scs/cclass/int/sx9b.html

which is clear enough on how to do it. It looks messy at first but it's probably the most straightforward way of doing it. I don't yet see how to access members of the array, but I'm one small test program away from figuring that out. I likely won't get to that part today.

No comments:

Post a Comment