|
It is called padding - the size of the structure is padded with empty space to optimize its access. A 32-bit system moves data in 32-bit chunks faster than data that is not sized at 32-bits.
Note tha packing may also impact the size of the structure - structure members are normally aligned in order to optimize their access (non-aligned access is allowed x86 architecture, but it takes a performance hit). 32-bit values are aligned to start at a 32-bit boundary, 16-bit values are aligned to a 16-bit boundary, etc. by moving the start of the structure in memory so that it lies on its natural boundary (32-bit boundary, for example).
struct STest
{
DWORD m_dwValue;
char m_cValue;
};
struct STest2
{
DWORD m_dwValue;
char m_cValue;
int m_iValue;
};
struct STest3
{
DWORD m_dwValue;
short m_siValue;
char m_cValue;
};
The sizes of the structures (with default 32-bit padding) are 8 , 12 and 8 bytes, respectively, and are layed out in memory as follows:
FF FF FF FF 61 <code>CC CC CC</code>
FF FF FF FF 61 <code>CC CC CC</code> 11 00 00 00
FF FF FF FF 12 34 7A <code>CC</code> Bold ed bytes are the padding/packing bytes.
When laying out the order of members in a structure, if you place them so that they are more likely to fall on their natural alignment, you can reduce the footprint of the structure.
You may have to force the packing of a structure when sharing serialized (saved to some medium) data between two different applications/systems, like when sending data over a socket to a server - both systems have to agree on the packing/padding of the data in order to read it correctly.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hello, I have a problem that I simply can't solve on my own.
Background:
I have a single document MFC application where the user may doubleclick on a piece of text and thereby call forth a dialog window for editing the text. That text is displayed in a Static text box. If I make a change to the text I can use Ctrl+Z or Ctrl+Y to Undo/Redo and that is great but some users do not know all short-commands so I also want to make an Undo button and a Redo button to do the exact same things. Outside the dialog in my application the accelerators Ctrl+Z and Ctrl+Y are tied to my own-defined Undo/Redo functions that are specific to my application so how do I find out what events the Ctrl+Z and Ctrl+Y accelerators in the dialog triggers?
Problem:
Since Ctrl+Z/Ctrl+Y works in my dialog although they are not defined in my IDR_MAINFRAME Accelerators they must obviously be connected to functions that are specific for performing Undo and Redo in a Dialog window. How do I connect those functions to two Undo Redo buttons as well?
Visual Studio version:
Microsoft Visual Studio 2003
|
|
|
|
|
The standard edit control has its undo/redo functionality built it, just as the Rich Edit control does - you do not really have to do anything to and you get it for free.
You can implement the button handlers so that they send EM_UNDO messages to the edit control. Lookup the EM_UNDO message for more details.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks a bunch, that was just the info I neeeded!
|
|
|
|
|
How can i hide from user my "h" files and "cpp" files ?
I have a visual c++ 6.0 project , CDialog base aplication what can i do ?
Bravoone
|
|
|
|
|
i don't understand...
who is the "user" ?
a user of the application, or another developper that will have to use your code, but whom you want to hide the implementation details ?
|
|
|
|
|
a user of the application!
Bravoone
|
|
|
|
|
so, how could a user of the application get your source files (.h and .cpp) ???
do you used to distribute them with your exes ?
|
|
|
|
|
THIS IS MY QUESTION what can i do to hide my files from the user ?
Bravoone
|
|
|
|
|
you don't have to !!! where would he get them from ?!?!
and you didn't answer mine : do you used to distribute them with your exes ?
if yes, i really don't understand why ! an exe is standalone (regarding of the source codes)
|
|
|
|
|
please can you tell me more ... what files i must distribute for user ?
Bravoone
|
|
|
|
|
|
ok ! i glad you enjoy but this not help me !!!
what files? "obj","sbr","rc" ?
Bravoone
|
|
|
|
|
.exe !!! unless you don't build for Windows plateforms ?
dude, what files do you double click on when you start a program ?
seriously, are you on drugs ? or why are you so lost ?
oh, i forgot to say ; to have the exe, you must Build the solution (in release mode, it's better for a final delivery)
|
|
|
|
|
i now but not all CDialogs are displayed just the first CDialog the second the aplication will exit;
Bravoone
|
|
|
|
|
Dude, that's enough !
now if you have a problem, stop posting a single sentence question. write the whole problem ; explain in details what you have, what you already tried, where it issues...
we're not geniuses and we cannot guess what you're doing wrong if we have no cards to play with.
|
|
|
|
|
|
Bravoone_2006 wrote: Dude is working ...
what's working ?!
what did you do ?
|
|
|
|
|
I want some of what he's smoking
|
|
|
|
|
buddy, be careful, it seems to be very very hard !
or he turned troll ?! strange
|
|
|
|
|
I actually found myself admiring your restraint on this one.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
|
|
|
|
|
|
toxcct wrote: what did you do ?
He stopped distributing the source code files. I need to start thinking outside the box more, as that solution never occurred to me.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
that's funny, it's the first time i see someone delivering source codes expecting the user to compile the application before the first use
DavidCrow wrote: I need to start thinking outside the box more
Welcome to the Codeproject David... If i'm of any help
|
|
|
|
|
toxcct wrote: t's the first time i see someone delivering source codes expecting the user to compile the application before the first use
You are obviously no Linux-Expert.
They actually have whole Distributions where you Compile the whole thing from the ground up.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|