| | |
typedef or a multidimensional array?
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2007
Posts: 7
Reputation:
Solved Threads: 0
Hi,
my name is Andrew. I believe this will be my first post on daniweb so please bear with me.
I'm working on a compression algorithm (miniSEED steim 2 compression if anyone is interested, its for seismic lossless compression) in C so I do a lot of bit manipulation of the data. I need to save the data in a record that has 64 64-byte frames. The first frame is header information. The second frame is where all the real data begins to be stored. Each frame contains 16 32-bit words (or subframes).
So I've created a Record structure that contains a header struct and a new data type of 64 bytes. My issue arises when i do my compression algorithm and I'm trying to transfer the 64 bytes from my temporary frame storage to the corresponding frame in the record structure.
Here's the code to help clarify what I'm talking about.
Right now I'm using typedef and to copy over the
Thanks in advance,
Andrew
my name is Andrew. I believe this will be my first post on daniweb so please bear with me.
I'm working on a compression algorithm (miniSEED steim 2 compression if anyone is interested, its for seismic lossless compression) in C so I do a lot of bit manipulation of the data. I need to save the data in a record that has 64 64-byte frames. The first frame is header information. The second frame is where all the real data begins to be stored. Each frame contains 16 32-bit words (or subframes).
So I've created a Record structure that contains a header struct and a new data type of 64 bytes. My issue arises when i do my compression algorithm and I'm trying to transfer the 64 bytes from my temporary frame storage to the corresponding frame in the record structure.
Here's the code to help clarify what I'm talking about.
C Syntax (Toggle Plain Text)
//Here's the excerpt from my miniSEED.h #define MAXSEEDFRAMES 7 //7 for 512, 63 for 4096 #define MAXWORDSPERFRAME 16 typedef int compressed_frame[MAXWORDSPERFRAME]; typedef struct { mSEED_header head; compressed_frame frames[MAXSEEDFRAMES]; } mSEED_record; typedef struct mSEED_secBuf { mSEED_record *rec_ptr; //some pointer to the seed data frame int subframe[MAXWORDSPERFRAME]; // temp array to hold frame data int channel; // Determines which channel's frame int ori_dnib; // Subframe formatting int new_dnib; int data_buffer[7]; // Compressed data pre-storage int buff_count; // The current buffer position int sub_count; // The current subframe being written to int frame_count; // The current frame # being written to int fwd_int_const; // Forward Integration Constant int rev_int_const; // Reverse Integration Constant } mSEED_data, *pmSEED_data; //heres the excerpt where i copy the data over // store the dnib code, if buffer has enough data, fill the subframe if(steim_concat(p_msDAT)) { fill_subframe(p_msDAT); memcpy(p_msDAT->subframe, p_msDAT->rec_ptr->frames[p_msDAT->frame_count], (sizeof(int)*MAXWORDSPERFRAME)); }
Right now I'm using typedef and to copy over the
mSEED_data.subframe to the mSEED_record.frames[x] . I use memcpy. Would a multidimensional array better serve my purposes or is it simply a matter of style?Thanks in advance,
Andrew
> to copy over the mSEED_data.subframe to the mSEED_record.frames[x] . I use memcpy
Except your code is copying the other way...
Besides, the final sizeof should have been
>
Saying
Though if you made it a struct, like this
Then you would be able to do
as a straigh-forward structure assignment.
The downside is that everywhere else now has to have "
> Would a multidimensional array better serve my purposes or is it simply a matter of style?
Despite the typedef, a 2D array is exactly what you have at the moment. It is functionally no different to saying
Thanks for using the code tags, so few people seem to manage it on their first post that it's a rare treat worthy of comment.
Except your code is copying the other way...
Besides, the final sizeof should have been
sizeof(compressed_frame) to maximise the benefit of using the typedef.>
int subframe[MAXWORDSPERFRAME];Saying
compressed_frame subframe; would have been more in keeping with your efforts elsewhere.Though if you made it a struct, like this
C Syntax (Toggle Plain Text)
typedef struct { int frame[MAXWORDSPERFRAME]; } compressed_frame;
p_msDAT->subframe = p_msDAT->rec_ptr->frames[p_msDAT->frame_count];as a straigh-forward structure assignment.
The downside is that everywhere else now has to have "
.frame[pos]" member access.> Would a multidimensional array better serve my purposes or is it simply a matter of style?
Despite the typedef, a 2D array is exactly what you have at the moment. It is functionally no different to saying
int frames[MAXSEEDFRAMES][MAXWORDSPERFRAME];Thanks for using the code tags, so few people seem to manage it on their first post that it's a rare treat worthy of comment.
I don't know, in general, c doesn't guarantee really much concerning the exact layout of the structure in memory. So, using memcpy for structures, is likely not so good idea... The only good way to copy structures in c, is member by member. Therefore certainly, if something can be implemented as a multidimensional array, then it should be done so, all the copying and writing would be easier then.
Knowledge is regarded by the fool as ignorance, and the things that are profitable are to him hurtful. He liveth in death. -- Thoth the Atlantean
![]() |
Similar Threads
- Multidimensional array sort problem (C++)
- Question regarding multidimensional array for navigation bar (Graphics and Multimedia)
- Synchronized Multidimensional Array (Java)
- Sort multidimensional array on more than one column? (ASP)
- multidimensional array merge using PHP (PHP)
- How to Sort a MultiDimensional Array (C)
- multidimensional array (C)
- Java Multidimensional Arrays (Java)
Other Threads in the C Forum
- Previous Thread: file and multidimensional array
- Next Thread: Assmbler implementation using C
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation overwrite owf pdf pointer pointers posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






