Lecture 8/12: Data Alignment

  Рет қаралды 71,825

hhp3

hhp3

Күн бұрын

Пікірлер: 65
@MrVecheater
@MrVecheater 5 жыл бұрын
Harry Porter and the Order of the data
@jayanthibalasubramanian4841
@jayanthibalasubramanian4841 5 жыл бұрын
haha
@MicheleTurchiarelli
@MicheleTurchiarelli 5 жыл бұрын
My idol hahahah
@harryjohnsonperu724
@harryjohnsonperu724 4 жыл бұрын
Harry Porter of Portland
@tuesdaypeacock
@tuesdaypeacock 2 жыл бұрын
Welcome to Halfword school.
@hamzakhalid4536
@hamzakhalid4536 2 жыл бұрын
Alohomora!
@itsabhijeetanand
@itsabhijeetanand 3 жыл бұрын
I got clarity after watching your video. Thanks a lot for explaining in a very simpler form .
@DFsdf3443d
@DFsdf3443d 6 жыл бұрын
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?
@ApplePotato
@ApplePotato 6 жыл бұрын
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.
@DavePoo
@DavePoo 6 жыл бұрын
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
@MrVecheater
@MrVecheater 5 жыл бұрын
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
@RegularObamahedron
@RegularObamahedron 4 жыл бұрын
@@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
@OpenGL4ever
@OpenGL4ever 6 ай бұрын
It even matters on an 8086, but it will effectively not matter on an 8088.
@zubiarfan
@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.
@OpenGL4ever
@OpenGL4ever 6 ай бұрын
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.
@ziaullahkhankhail2461
@ziaullahkhankhail2461 3 ай бұрын
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.
@alexobzor
@alexobzor 2 жыл бұрын
Thank you very much! Fast and good explanation instead of dry and strict info from wiki
@hhp3
@hhp3 2 жыл бұрын
Glad you liked it
@LearnKinyarwanda
@LearnKinyarwanda 4 жыл бұрын
Brilliant explanation. Thank you for educating us.
@Untitled0078
@Untitled0078 2 жыл бұрын
What is the reason behind all of this?
@OpenGL4ever
@OpenGL4ever 6 ай бұрын
Performance.
@elijaheinstein160
@elijaheinstein160 Жыл бұрын
but why is this alignment required?
@ryanfang7827
@ryanfang7827 Жыл бұрын
The goal for this is to simplify the memory access.
@OpenGL4ever
@OpenGL4ever 6 ай бұрын
1. it allows simpler MMUs. Thus the CPU will cost less. 2. It is better for performance.
@sweetness583
@sweetness583 6 жыл бұрын
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?
@aqua3418
@aqua3418 3 жыл бұрын
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.
@OpenGL4ever
@OpenGL4ever 6 ай бұрын
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.
@arshidsayyad2232
@arshidsayyad2232 8 жыл бұрын
I want ur notes sir...!
@mrkanet
@mrkanet 6 жыл бұрын
Hi. Can i get your worksheets?
@bandrefilipe
@bandrefilipe Ай бұрын
I still didn't understand what the red colored addresses mean
@qhrunknown
@qhrunknown 3 күн бұрын
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.
@nullzero9224
@nullzero9224 3 жыл бұрын
This is where vid + comments draw the full picture - Thanks for all
@Raphamerlo
@Raphamerlo 4 ай бұрын
Great video!!! Thank you!
@kataiho2192
@kataiho2192 8 жыл бұрын
Is this for a 32 bit machine?
@primitiveinds
@primitiveinds 8 жыл бұрын
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.
@eileenrabbit3367
@eileenrabbit3367 3 жыл бұрын
Isn't a word is 2 byte? Why is it 4 byte in your example?
@aqua3418
@aqua3418 3 жыл бұрын
Half-word is 2 bytes
@eileenrabbit3367
@eileenrabbit3367 3 жыл бұрын
@@aqua3418 doubleword is 4 bytes,word is 2 byte
@aqua3418
@aqua3418 3 жыл бұрын
@@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
@eileenrabbit3367
@eileenrabbit3367 3 жыл бұрын
@@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 👍
@iamhereblossom1588
@iamhereblossom1588 2 жыл бұрын
Hello, so what's the correct size for a word?
@mihaistoian_
@mihaistoian_ 5 жыл бұрын
Thank you! I'm now understanding!
@dart-kotlin-dev
@dart-kotlin-dev Жыл бұрын
Blimey, it's *HARRY POTTER*
@jixuancheng
@jixuancheng Жыл бұрын
Thanks a lot❤ 4:16
@tomizzo11
@tomizzo11 9 жыл бұрын
Great video
@pajeetsingh
@pajeetsingh 3 жыл бұрын
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.
@hargunbeersingh8918
@hargunbeersingh8918 3 жыл бұрын
You need to look up the memory allocation algorithm for whatever compiler you are using
@MarcoAurelio-sv2tk
@MarcoAurelio-sv2tk 5 ай бұрын
Old schoold paper ahah excelent engineer for sure
@THVLPLYR
@THVLPLYR 2 жыл бұрын
Very helpful! thank you!!
@lailabujasim4078
@lailabujasim4078 5 жыл бұрын
so helpful .. thaaank you
@pourya7294
@pourya7294 9 ай бұрын
thanks a lot
@960peps
@960peps 7 жыл бұрын
Very helpful
@lilkamal8607
@lilkamal8607 3 жыл бұрын
thanks ❤️
@manuchaudhary7902
@manuchaudhary7902 6 жыл бұрын
thank you sir
@ashukiller2216
@ashukiller2216 4 жыл бұрын
👍👍👍👍👍👍👍👍
@arthurcueva
@arthurcueva 4 жыл бұрын
yeahhh trank you !!! 2020
@tomislav078
@tomislav078 5 жыл бұрын
Thank you.
@ranaislam1291
@ranaislam1291 7 жыл бұрын
Help full like it
@soldadopreciso
@soldadopreciso 6 жыл бұрын
please activate closed captions to non-English native people , greetings from Ecuador (Spanish )
@doezage
@doezage 3 жыл бұрын
Harry porter
@RajeshmayBurman
@RajeshmayBurman Жыл бұрын
Data trump
Ep 078: Data Structure Alignment and Endianness
12:19
Intermation
Рет қаралды 19 М.
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.
Vampire SUCKS Human Energy 🧛🏻‍♂️🪫 (ft. @StevenHe )
0:34
Alan Chikin Chow
Рет қаралды 138 МЛН
How to have fun with a child 🤣 Food wrap frame! #shorts
0:21
BadaBOOM!
Рет қаралды 17 МЛН
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,5 МЛН
i wrote my own memory allocator in C to prove a point
5:23
Low Level
Рет қаралды 408 М.
Structure Padding in C
8:42
Neso Academy
Рет қаралды 254 М.
Comparing C to machine language
10:02
Ben Eater
Рет қаралды 5 МЛН
Lecture 3/12: Bits, Bytes and Words
15:07
hhp3
Рет қаралды 150 М.
Endianness Explained
4:43
Aaron Yoo
Рет қаралды 22 М.
Assembly 35: Memory Alignment - What is it?
24:09
Bill Sky - The Computer Guy!
Рет қаралды 794
Data ALIGNMENT in C++
4:23
Lukasz Lipski
Рет қаралды 7 М.
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.