memory alignment and structure padding
hi i m wondering what is memory alignment and structure padding i was reading some book on c and got to bitfields structure and talks abt structure padding and its used to align memory i don't even know what's memory alignment means could someone please explain to me there concept ? in details
thanks in advanced.
Re: memory alignment and structure padding
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding. As size of pointer is 4 bytes, if everything is organized by multiple of 4, that it will be easier and faster to calculate the address and processing them. As structures are used to club different size variables, compiler will align to 4 byte boundaries and for that it needs padding. When you are using C, structure padding is used to pad the data in such a way that it can be sent to external devices. Structure Padding is done to do memory alignment.
Re: memory alignment and structure padding
Although the compiler (or interpreter) normally allocates individual data items on aligned boundaries, data structures often have members with different alignment requirements. To maintain proper alignment the translator normally inserts additional unnamed data members so that each member is properly aligned. In addition the data structure as a whole may be padded with a final unnamed member. This allows each member of an array of structures to be properly aligned.