Click here to Skip to main content
15,900,662 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: interact between 2 process - urgent!!!! Pin
CPallini17-Jan-09 9:43
mveCPallini17-Jan-09 9:43 
GeneralRe: interact between 2 process - urgent!!!! Pin
Luc Pattyn17-Jan-09 9:55
sitebuilderLuc Pattyn17-Jan-09 9:55 
GeneralRe: interact between 2 process - urgent!!!! Pin
Luc Pattyn17-Jan-09 9:57
sitebuilderLuc Pattyn17-Jan-09 9:57 
JokeRe: interact between 2 process - urgent!!!! Pin
CPallini17-Jan-09 22:30
mveCPallini17-Jan-09 22:30 
QuestionProblem with record reading from a binary file Pin
Umer Aziz17-Jan-09 1:05
Umer Aziz17-Jan-09 1:05 
AnswerRe: Problem with record reading from a binary file Pin
Garth J Lancaster17-Jan-09 1:10
professionalGarth J Lancaster17-Jan-09 1:10 
AnswerRe: Problem with record reading from a binary file Pin
Stuart Dootson17-Jan-09 1:16
professionalStuart Dootson17-Jan-09 1:16 
GeneralRe: Problem with record reading from a binary file Pin
Luc Pattyn17-Jan-09 4:24
sitebuilderLuc Pattyn17-Jan-09 4:24 
Hi,

as the others said, there is some padding going on, i.e. the compiler skips a few byte positions by inserting NULL bytes, in order to get everything "naturally aligned", meaning a struct member with size n (n=1/2/4/8) should reside at an offset that is a multiple of n.

you typically don't have to worry about this, unless:
1. you need a lot of those structs, so memory usage becomes important
2. you have a union with another struct and expect things to overlap in a specific way
3. you are going to pass the struct to some other code (is basically same as 2)
4. you need to follow a certain data layout, maybe in a file or in a byte stream to/from a device

you can get a more compact struct by:
1. using a compiler switch or a pragma to tell the compiler not to perform natural alignment (not always
a good idea)
2. reordering your struct members, biggest first (not always acceptable) unless you happen to have
one whose size isn't a power of 2 (an array, another struct!), then biggest first but filling
the gaps yourself with the smaller ones.

BTW: structs themselves also get naturally aligned in memory; assume a struct with 14 useful bytes,
but due to its layout, it reports a size of 16; even when you manage to reorganize it so it shows
size=14, it will be located at an address that is a multiple of 16, so it will most probably effectively
occupy 16 bytes after all.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

I use ListBoxes for line-oriented text output (not TextBoxes), and PictureBoxes for pictures (not drawings).


AnswerRe: Problem with record reading from a binary file Pin
Umer Aziz17-Jan-09 18:21
Umer Aziz17-Jan-09 18:21 
QuestionBlum-Blum-Shub Pin
RomTibi17-Jan-09 0:04
RomTibi17-Jan-09 0:04 
AnswerRe: Blum-Blum-Shub Pin
Garth J Lancaster17-Jan-09 0:30
professionalGarth J Lancaster17-Jan-09 0:30 
GeneralRe: Blum-Blum-Shub Pin
RomTibi17-Jan-09 2:55
RomTibi17-Jan-09 2:55 
GeneralRe: Blum-Blum-Shub Pin
Garth J Lancaster17-Jan-09 15:39
professionalGarth J Lancaster17-Jan-09 15:39 
GeneralRe: Blum-Blum-Shub Pin
RomTibi17-Jan-09 22:39
RomTibi17-Jan-09 22:39 
GeneralRe: Blum-Blum-Shub Pin
RomTibi18-Jan-09 7:55
RomTibi18-Jan-09 7:55 
JokeYaba-daba-du! Pin
CPallini17-Jan-09 5:08
mveCPallini17-Jan-09 5:08 
GeneralRe: Yaba-daba-du! Pin
Garth J Lancaster17-Jan-09 15:28
professionalGarth J Lancaster17-Jan-09 15:28 
GeneralRe: Yaba-daba-du! Pin
RomTibi17-Jan-09 22:42
RomTibi17-Jan-09 22:42 
GeneralRe: Yaba-daba-du! Pin
RomTibi17-Jan-09 22:41
RomTibi17-Jan-09 22:41 
GeneralRe: Yaba-daba-du! Pin
ThatsAlok18-Jan-09 18:15
ThatsAlok18-Jan-09 18:15 
GeneralRe: Yaba-daba-du! Pin
RomTibi21-Jan-09 7:52
RomTibi21-Jan-09 7:52 
Questionmultithread Pin
RomTibi17-Jan-09 0:02
RomTibi17-Jan-09 0:02 
AnswerRe: multithread Pin
Garth J Lancaster17-Jan-09 0:41
professionalGarth J Lancaster17-Jan-09 0:41 
GeneralRe: multithread Pin
RomTibi17-Jan-09 2:43
RomTibi17-Jan-09 2:43 
QuestionDisk operation performance question [modified] Pin
followait16-Jan-09 23:07
followait16-Jan-09 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.