| Thread Closed |
Alignment of Stack |
Share Thread | Thread Tools |
| Dec16-07, 04:02 AM | #1 |
|
|
Alignment of Stack
What is alignment of a stack? And why is it important to align a stack when working on an x86 processor?
|
| Dec16-07, 12:24 PM | #2 |
|
|
|
| Dec17-07, 12:40 AM | #3 |
|
|
I had googled for the same yesterday and found the link but I didnt understand why that happens... anyways, i am attaching the piece of code the i found initially.... the file was supposed to be align.h but i dont know if the messageboard would accept upload of formats other than the given ones....
|
| Dec18-07, 01:26 AM | #4 |
|
Recognitions:
|
Alignment of Stack
Alignment of data in memory is to make sure that data is meaningfully "aligned" in the memory, because when the CPU fetches data, it doesn't fetch one bit or one byte, it fetches a few bytes, maybe 2, 4, 8, or 16 depending on your CPU. If one of your variables you want to perform an operation on is in two "segments", your CPU will then for example need to fetch twice.
In fact it's usually important on any processor. In some processors it's not only recommended to keep the stack aligned, it's required. I suppose the stack is more "special" in the fact that it is only created at runtime instead of being preallocated. You can read more about its significance in Wikipedia under 'data structure alignment'. |
| Dec18-07, 09:24 AM | #5 |
|
|
Its not necessarily the alignment of the stack itself, but the address of each variable stored on the stack that the header file deals with.
Addresses in memory are odd, even, or are "aligned" meaning the address divides with no remainder, on different boundaries. Those boundaries can be 2 (bytes), 4, 8, 16... page. A page is defined by the system but could be 4096 bytes - for example. In some systems accessing a variable with a non-aligned address can cause a fatal bus error, result in bad performance, or interfere with caching memory. |
| Thread Closed |
| Thread Tools | |
Similar Threads for: Alignment of Stack
|
||||
| Thread | Forum | Replies | ||
| Work required to stack books | Introductory Physics Homework | 14 | ||
| How is stacking accomplished and Why do we stack data? | General Physics | 1 | ||
| Velocity stack | Mechanical Engineering | 4 | ||
| A stack of books (conflicting answers) | Introductory Physics Homework | 1 | ||
| Cooling Stack Shape | Computing & Technology | 3 | ||