I got clarity after watching your video. Thanks a lot for explaining in a very simpler form .
@DFsdf3443d6 жыл бұрын
but why? why not just store one word at address 0x5 and then the next at 0x9 and so on ? what does this alignment achieve?
@ApplePotato6 жыл бұрын
Alignments has something to do with how memory is accessed by the CPU. For example you have 8 bytes of data and some CPU that can only read 64bits chunk of data at a time from RAM. If your data is not aligned it mean it is store across 2 different 64bit chunks. First of all it will result in slow memory access because you have to read 2 chunks instead of 1. Some architectures in order to simplify the design of the MMU will not even allow you to do this and will throw an exception.
@DavePoo6 жыл бұрын
You ask a good question. This video tells you what memory alignment is but doesn't say why the data needs to be aligned. ApplePotato is on the right lines with his answer. This video is just telling us something, but we are not learning anything because we are not sure why what we have been told is true. Even, the statement that the "memory must be aligned" is false, because you can writing working programs with misaligned data. You just need to be aware what are the consequences of doing that. I present a working program using misaligned memory: ideone.com/2Jrffk
@MrVecheater5 жыл бұрын
A 64 bit CPU likely has a word length (amount of data it reads at once) of 64 bit = 8 bytes). So it makes no sense to address only a certain byte. It will read 8 bytes at once regardless. Also it would make the circuit more complex and expensive If a 4 byte integer starts at 0x5, it ends at 0x8 and will exceed the address range of the first word (0x0 - 0x7). This would result in 2 read operations. Except that some CPUs can't handle this situation in the first place
@RegularObamahedron4 жыл бұрын
@@ApplePotato This video and this comment has answered so many questions that I had that for some reason my assigned reading would not answer. Much, much thanks
@OpenGL4ever6 ай бұрын
It even matters on an 8086, but it will effectively not matter on an 8088.
@zubiarfan Жыл бұрын
Question: In 64-bit architecture the size of a word is 8 bytes. So does that mean that a word (8 bytes) has to be divisible by 8 and a doubleword by 16 assuming that doubleword is 16 bytes? Also in a 64-bit context is halfword 32 bits (4 bytes)? Would appreciate an answer and thanks for the video.
@OpenGL4ever6 ай бұрын
General rule: If you want to store an n-byte value the starting address of that value should be dividable by n. 64 Bit architecture: 8 byte data type= address must be dividable by 8 4 byte data type = address must be dividable by 4 16 byte data type = address must be dividable by 16 For historical reasons, the following naming convention exists on the x86 architecture: 1 nibble = 4 Bits 1 Byte = 1 Byte 1 Word = 2 Bytes 1 Double Word = 4 Bytes 1 Quadruple Word = 8 Bytes 1 Double Quadruple Word = 16 Bytes I would therefore not refer to a 64-bit value on a 64-bit x86 processor as a word, as this would lead to confusion.
@ziaullahkhankhail24613 ай бұрын
Byte (8-bit): Can be stored at any address. Word (16-bit): Should be stored at addresses that are multiples of 2. Double Word (32-bit): Should be stored at addresses that are multiples of 4. Quad Word (64-bit): Should be stored at addresses that are multiples of 8.
@alexobzor2 жыл бұрын
Thank you very much! Fast and good explanation instead of dry and strict info from wiki
@hhp32 жыл бұрын
Glad you liked it
@LearnKinyarwanda4 жыл бұрын
Brilliant explanation. Thank you for educating us.
@Untitled00782 жыл бұрын
What is the reason behind all of this?
@OpenGL4ever6 ай бұрын
Performance.
@elijaheinstein160 Жыл бұрын
but why is this alignment required?
@ryanfang7827 Жыл бұрын
The goal for this is to simplify the memory access.
@OpenGL4ever6 ай бұрын
1. it allows simpler MMUs. Thus the CPU will cost less. 2. It is better for performance.
@sweetness5836 жыл бұрын
Isn't most data going to be unaligned? If data is aligned with addresses that are multiples of 4 lets say, then what about all the memory addresses that are not multiples of 4? Do you just not use those addresses? Wouldn't that be a big waste of memory?
@aqua34183 жыл бұрын
Correct, it's memory inefficient. It trades memory inefficiency for CPU efficiency (speed). Alternatively, you could pack your data, but it would be the opposite: it would be memory efficient, but CPU inefficient.
@OpenGL4ever6 ай бұрын
Modern compilers will use padding, thus if you put a 1 byte data type in a struct, followed by a normal 4 byte data type, the compiler will fill up the 3 bytes after the first 1 byte with empty space. Thus it will waste main memory to increase performance.
@arshidsayyad22328 жыл бұрын
I want ur notes sir...!
@mrkanet6 жыл бұрын
Hi. Can i get your worksheets?
@bandrefilipeАй бұрын
I still didn't understand what the red colored addresses mean
@qhrunknown3 күн бұрын
It is examples to demonstrate proper alignment. At 1:30, if a 1-word variable is stored at address 0000 0004, it occupies 4 bytes, addresses 0000 0004 to 0000 0007 (1 word == 4 bytes), and the same applies when stored at 0000 0000, it occupies addresses 0000 0000 to 0000 0003. The red addresses indicates a 1-word variable that is proper aligned.
@nullzero92243 жыл бұрын
This is where vid + comments draw the full picture - Thanks for all
@Raphamerlo4 ай бұрын
Great video!!! Thank you!
@kataiho21928 жыл бұрын
Is this for a 32 bit machine?
@primitiveinds8 жыл бұрын
Ideally the only thing that changes between 32 and 64 bits is the size of pointer members in structs; 4 bytes for 32 bit, 8 bytes for 64 bit.
@eileenrabbit33673 жыл бұрын
Isn't a word is 2 byte? Why is it 4 byte in your example?
@aqua34183 жыл бұрын
Half-word is 2 bytes
@eileenrabbit33673 жыл бұрын
@@aqua3418 doubleword is 4 bytes,word is 2 byte
@aqua34183 жыл бұрын
@@eileenrabbit3367 Whatever references I saw before must've been wrong 😏 People really need to get their details right. This is not the first time I've seen videos with half-baked and inaccurate info
@eileenrabbit33673 жыл бұрын
@@aqua3418 true,I've already done with my exams but during it when I was watching these tutorials ,sadly,there is lots of incorrect information:( Good luck 👍
@iamhereblossom15882 жыл бұрын
Hello, so what's the correct size for a word?
@mihaistoian_5 жыл бұрын
Thank you! I'm now understanding!
@dart-kotlin-dev Жыл бұрын
Blimey, it's *HARRY POTTER*
@jixuancheng Жыл бұрын
Thanks a lot❤ 4:16
@tomizzo119 жыл бұрын
Great video
@pajeetsingh3 жыл бұрын
malloc(sizeof(char)), malloc(sizeof(double)), malloc(sizeof(short)) and all other primitives gives addresses ending in 0xXXXXXXXXXXX0. char* c = (char*)malloc(sizeof(char)); //c = 0xXXXXXXXXXXa0 double* d = (double*)malloc(sizeof(double)); //d = 0xXXXXXXXXXXb0 So there is 16 bytes of hole between char and double. Do you know why 16? Machine is 64 bit Mac.
@hargunbeersingh89183 жыл бұрын
You need to look up the memory allocation algorithm for whatever compiler you are using
@MarcoAurelio-sv2tk5 ай бұрын
Old schoold paper ahah excelent engineer for sure
@THVLPLYR2 жыл бұрын
Very helpful! thank you!!
@lailabujasim40785 жыл бұрын
so helpful .. thaaank you
@pourya72949 ай бұрын
thanks a lot
@960peps7 жыл бұрын
Very helpful
@lilkamal86073 жыл бұрын
thanks ❤️
@manuchaudhary79026 жыл бұрын
thank you sir
@ashukiller22164 жыл бұрын
👍👍👍👍👍👍👍👍
@arthurcueva4 жыл бұрын
yeahhh trank you !!! 2020
@tomislav0785 жыл бұрын
Thank you.
@ranaislam12917 жыл бұрын
Help full like it
@soldadopreciso6 жыл бұрын
please activate closed captions to non-English native people , greetings from Ecuador (Spanish )