Structure Padding in C
Vložit
- čas přidán 17. 09. 2019
- C Programming: Structure Padding in C Programming.
Topics discussed:
1) Memory allocation to Structures.
2) Need for Structure Padding.
3) The concept of Structure Padding.
C Programming Lectures: goo.gl/7Eh2SS
Follow Neso Academy on Instagram: @nesoacademy(bit.ly/2XP63OE)
Follow me on Instagram: @jaspreetedu(bit.ly/2YX26E5)
Contribute: www.nesoacademy.org/donate
Memberships: bit.ly/2U7YSPI
Books: www.nesoacademy.org/recommende...
Website ► www.nesoacademy.org/
Forum ► forum.nesoacademy.org/
Facebook ► goo.gl/Nt0PmB
Twitter ► / nesoacademy
Music:
Axol x Alex Skrindo - You [NCS Release]
#CProgrammingByNeso #CProgramming #StructuresInC #StructurePadding #Structure&Union
speachless!! you are soooo goood in explainging. thanks a lot
Yes agree.
your style of pedagogy has helped me in overcoming phobia of coding.
the sort of knowledge you are imparting is enriching our lives.
thanx a ton & we look forward to having more such amazing content.
kudos to you.
Brilliant! I particularly liked the repetition when driving home a particularly important point. Superb work (and exactly what I was looking for - was searching for a good detailed explanation on structure storage in memory).
Tnx
Thank you very much! I understood it. I Love the format you chose for the video, a black background, a representation of the memory bytes and everything was explained in a very direct and simple way.
Ok
This was the best. Saw many tutorials, but understood the concept here in one go. I rarely comment on videos, but really had to appreciate you here. Thanks man!
I couldn't agree with you more , It's awesome how he explained it.
Perfect video to understand the importance of padding and its uses.
Thanks God ! Your video saves my embedded programming career
ờ mây zing gút chóp
Ok
Explained very detailed, Cleared every doubt.
Thank you
Thank you sir for clearing the concept in such an easy way...
Such an amazing explanation! You made it so simple to understand, thank you :)
Thank you sir. Keep posting more on stacks, queues, linked lists
Excellent explanation, thanks for your dedicated time in creating these videos. Regards from Mexico.
Thanks for the wonderful explanation.
trying to read how this works is way harder than having pictures and someone explaining. Thank you.
Padding is not defined in the C (or C++) standard. This behavior depends on the compiler. It can also be configured too. For example, VC++ has the /Zp and #pragma pack options while GCC has -fpack-struct option.
It is a good habit to put first the biggest type in ascending order to help compilator !
just awesome bro you have explained very well
really easy to understand for me. thanks a lot!!
Best explanation of the concept. Thank you so much.
Sir it is a good class for me. Thank you sir,upto now I didn't no the background allocation of memory now I got clarified. SIR ONE MORE THING, I WANT TO sll,dll,cll,sporting techniques tree's,graphs,bss. Pls... upload sir, one of ur student, thank you sir.
crystal clear explanation, thanks a lot :)
its has been clear. thanks Sir
wow great one presentation sir..
Very useful video...Thank you sir.please try to put more videos in advanced c topics..
You are one of my favorite sources for c programming concepts. I know that if you have a video on the subject then I will be able to understand that concept. Thank you!
Ok
Good, clear explanation!
you make every concept so easyyyyyyyyy.
Great explanation Sir..
Thank you so much for detailed explanation.....
Missing to explain __attribute__((packed)) with unaligned memory access which is possible (with ARM).
#pragma pack(1)
Amazing explanation. Thank you 😃
something unique and new things I have learned💕💕
Amazing initiative by neso academy
Great Explanation!!
Awesome explanation, thanks for sharing
Excellent Explanation. All cleared
Very good, just loved it
very nice explained....thank you sir 🤝.....
Life saving! Ty
Awesome Explanation sir,Thank you
very helpful video.....so good explanation
Very Helpfull...Thank You :)
Great explanation.
Very Interesting!...
Thank u sir! I have a question, if there is another struct , say def, can def's char member d be written adjacent to abc's c
Well explained, thank you so much
Great video
Excellent video my friend
Excellent job
Amazing
Very well explained. Thanks!
amazing!
Very well explained, thank you sir
Amazing explanation
excellent lecture i have ever seen
Excellent explanation 👍
amazing thanks so much
Excellent👍
Awsome xplanation😍
Best explanation
Amazing 🤩
excellent explanation
For example, with ARM architecture (it's 8bit addressable and 32 bit accessible) engineers and programmers are encouraged to use 32 bit values all the time, so software will run faster and more secure. If memory space is critical then optimization is needed.
It is all about time and space.
Very nice explanation thank you
wow bro just thank you
Amazing...
thank you so much
Thank you sir...😃😇
Wonderful ❤
thx for the super nice video
thanks :) however its kind of confusing as you said you in 1 CPU cycle char a, char b and 2 bytes of int c can be accessed, when you access to main memory thats over 100 CPU cycles
Amazing, 😍😍
Silky smooth!
excellent excellent explanation ..I was having an issue wstructure memebers being read incorrectly and I was suspecting this padding issue. and I was wondering how to explain this to the team .may be I should link to this vedio .. lol ;)
Tqu sir.
Nice clarification 😍
Tq so much bro
Very helpful thanku
it is very helpful
Good explanation on structure padding
thank you
Dhanyavaad🙏
when declaring a char and then a double variable it should give 4+8=12 as output. But it shows 16. Can someone explain why?
thats called padding.
Your processor is 64 bit architecture may be
Crystal clear
You are really great. Plzz. Give a practical example nd make us clear how a software execute. Suppose i have one software on my mobile then how this software will be executed. Plz give us practical example from first to last.
well explained
Why is the compiler not allowed to rearrange member variables? If there's a consistent rule for this, then even external libraries will not face any ambiguity. That way, int variable could've been placed in front, and no wastage will be required and all 3 can be accessed in one CPU cycle.
Have you tried enabling optimizations with your compiler?
You are explaining 💯 times better than my college professor......
1000 bro
Is this applicable for type declarations in main function?
Very nice
thanks
What will the size of structure in this case if we assume 32 bit architecture system @Neso Academy sir
struct abc
{
char a;
double b;
}test;
I was thinking... Sure, the processor can only access a word at a time. But wouldn't it make sense to, like, displace the address of the struct a bit to access the integer? Like, in the first example... Rather than padd the first word, wouldn't be better to just add 2 to the address and access the integer right away?? Or this operation would cost too much clock-wise everytime?
Awesome work 👏
Lesson: we should be careful while arranging the srruct variables for better memory utilisation
Padding also becomes a portability issue when code is written on a system with different architecture then the architecture it is being run on. If you already knew this then my apologies. I just feel like understanding padding has more to do with writing portable code.
If we use one int,one double and again one int variable then the size of variable should be 16 but it is 24 why???
Because double is 8 bytes long, so the word size would be 8 bytes long. Hence 8*3 = 24 bytes
@@kumargaurav8234 your reply cleared every doubt i had thanks
I m having 8 yrs of experience. Noone Clarified the doubt lk u..thank you..expecting more content from you
😱
To handle the case where the memory words are in different memory pages the processor must either verify that both pages are present before executing the instruction or be able to handle a TLB miss or a page fault on any memory access during the instruction execution.
Source - Wikipedia
So if we have a variable of char type then it's size would be 4 bytes because that processor can access 4 bytes at a time, but it's not so why? Does this padding concept applicable for only stuctures? Can somebody explain....
bhaot hard sirjee
in case of a 64bit processor and the struct in the video ... the memory storage allocated will be 8 no matter the order of the members of the struct .... am i right ?