I've read the article. Thanks stampede.
This is the most important
Padding is only inserted when a structure member is followed by a member with a larger alignment requirement or at the end of the structure
....
One use for such "packed" structures is to conserve memory. For example, a structure containing a single byte and a four-byte integer would require three additional bytes of padding. A large array of such structures would use 37.5% less memory if they are packed, although accessing each structure might take longer. This compromise may be considered a form of space-time tradeoff.
I have a new question. My data structures are used to store CAD information, in example hundreds of thousands of 3D points (float x,float y, float, charmetadata, int other, short other1,etc) .
What is the best ?
1.- Review my structures to order them to find the small size. (even so I'm going to have more memory occupied but....)
2.- Using a pack ? This are going to do my program slower ?
Thanks
Added after 6 minutes:
Can you give me a last help ...
I have this two functions to save - load data to a stream
the_stream is a stringstream I create so:
char mybuffer [265536];
the_stream.rdbuf()->pubsetbuf(mybuffer,265536);
char mybuffer [265536];
the_stream.rdbuf()->pubsetbuf(mybuffer,265536);
To copy to clipboard, switch view to plain text mode
template <class TT_stream>
void W_stream::put (TT_stream &value) {
const char * buffer ;
buffer = reinterpret_cast<const char*> (&value);
the_stream.write(buffer,sizeof value);
}
template <class TTget_stream>
void W_stream::get(TTget_stream & value) {
char * buffer ;
buffer = reinterpret_cast< char*> (&value);
the_stream.read(buffer, sizeof value);
}
template <class TT_stream>
void W_stream::put (TT_stream &value) {
const char * buffer ;
buffer = reinterpret_cast<const char*> (&value);
the_stream.write(buffer,sizeof value);
}
template <class TTget_stream>
void W_stream::get(TTget_stream & value) {
char * buffer ;
buffer = reinterpret_cast< char*> (&value);
the_stream.read(buffer, sizeof value);
}
To copy to clipboard, switch view to plain text mode
What is your opinion, are going to run ok ? (thinking at read -store structures )
Thanks
Bookmarks