Jump to content


Check out our Community Blogs

Lance

Member Since 11 Dec 2008
Offline Last Active Dec 06 2013 08:47 AM
-----

#423273 Memory Alignment

Posted by Lance on 07 January 2009 - 07:23 PM

The following excerpts are from the Wiki page link of which has been posted by roboticforest.

RISC

Most RISC processors will generate an alignment fault when a load or store instruction accesses a misaligned address. This allows the operating system to emulate the misaligned access using other instructions.

x86 and x86-64

While the x86 architecture originally did not require aligned memory access and still works without it, SSE2 and x86-64 instructions on x86 CPUs do require the data to be 128-bit (16-byte) aligned and there can be substantial performance advantages from using aligned data on these architectures.


Most of the time, the padding will be done by a compiler when necessary. check sizeof(foo) (foo as defined in RobotGymnast's post), you will most likely get 8 instead of 5, because the compiler has done padding for you.

What a struct/class designer can do is to put similarly aligned data together, for example
struct Bar{
     char a;
     int i;
     char c;
     int j;
     short s;
};
would be a lot bigger than
struct Bar{
     char a;
     char c;
     short s;
     int i;
     int j;
};

Padding is something you need to know but rarely need to do it by yourself
  • 1


#419642 TServerSocket;TClientSocket - bc++b5

Posted by Lance on 27 December 2008 - 06:22 AM

I BCB sample code (when you install, make sure in checked samples), there is a simple client server socket example, you can work through it and get an idea of what you need to do.
  • 1


#415557 Game Loop - Need some help looping..

Posted by Lance on 13 December 2008 - 06:36 AM

And use it whenever it's logical. Why else it's there in the language at all?

But seriouly, can you elaborate on the bads of this language feature?

BTW, I wouldn't hesitate to use goto when I see reasonable.
  • 1


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download