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.
@devugoel86982 жыл бұрын
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!
@عليكيلاني-ي8د Жыл бұрын
I couldn't agree with you more , It's awesome how he explained it.
@WistrelChianti4 жыл бұрын
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).
@manazirahsan13512 жыл бұрын
Tnx
@ahamd194 жыл бұрын
speachless!! you are soooo goood in explainging. thanks a lot
@koperaljali32534 жыл бұрын
Yes agree.
@dono42 Жыл бұрын
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.
@andresvallelisboa55114 жыл бұрын
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.
@manazirahsan13512 жыл бұрын
Ok
@michaelhernandez2075 Жыл бұрын
trying to read how this works is way harder than having pictures and someone explaining. Thank you.
@anshhmehta2 жыл бұрын
Perfect video to understand the importance of padding and its uses.
@beeyou62202 жыл бұрын
I m having 8 yrs of experience. Noone Clarified the doubt lk u..thank you..expecting more content from you
@rakesh231rakesh2 жыл бұрын
😱
@sunilkumarreddy65375 жыл бұрын
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.
@manuelconte21272 жыл бұрын
It is a good habit to put first the biggest type in ascending order to help compilator !
@khoahuynh68842 жыл бұрын
It is always the Indian sensei that makes me understand.
@sujitsatpute37413 жыл бұрын
You are explaining 💯 times better than my college professor......
@SJ_462 жыл бұрын
1000 bro
@manoharbompella4184 жыл бұрын
Explained very detailed, Cleared every doubt. Thank you
@andistheinforitbutso75133 жыл бұрын
Awesome work 👏 Lesson: we should be careful while arranging the srruct variables for better memory utilisation
@pnuema1.6182 жыл бұрын
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.
@TechnoVisionTV2 жыл бұрын
Such an amazing explanation! You made it so simple to understand, thank you :)
@ArjanvanVught5 жыл бұрын
Missing to explain __attribute__((packed)) with unaligned memory access which is possible (with ARM).
@ivanleon61643 жыл бұрын
#pragma pack(1)
@adeshgaikwad21925 жыл бұрын
Thank you sir for clearing the concept in such an easy way...
@pnuema1.6182 жыл бұрын
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!
@manazirahsan13512 жыл бұрын
Ok
@paschikshehu79883 жыл бұрын
1:15 not necessarily wrong, just that 1-packing is not efficient
@nishantraj50204 жыл бұрын
you make every concept so easyyyyyyyyy.
@sohitgore29242 жыл бұрын
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
@kitanowitsch2 жыл бұрын
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.
@rakesh231rakesh2 жыл бұрын
It is all about time and space.
@gamerplayer948305 ай бұрын
What does addressable and accessable mean? and what is the difference could you please tell? couldnt find or understand from anywhere
@kitanowitsch5 ай бұрын
@@gamerplayer94830 When you write and when you read from the memory, respectively. Data is written by 8 bits into the memory and read by 32 bits. So if your 8 bit data is in 4th memory part of 32bit location, it will take 4 tries to access that particular byte. That's why it is important when you declare structs and any other type of data. More speed and more secure.
@gamerplayer948305 ай бұрын
@@kitanowitsch thank you very much, i understood! have a nice day
@santanacasas13 жыл бұрын
Excellent explanation, thanks for your dedicated time in creating these videos. Regards from Mexico.
@mcbotface5 жыл бұрын
Thank you sir. Keep posting more on stacks, queues, linked lists
@QuratulainAzhar9 ай бұрын
Amazing 🤩
@05_abhisheksharma134 жыл бұрын
Amazing initiative by neso academy
@ronnieahabwomugisha52835 жыл бұрын
its has been clear. thanks Sir
@ashwanirajput91412 жыл бұрын
If we declear one more "char" var outside of struct. Then memory allocation for that var is where. 1. Just after var C " 10th place ". 2. 13th place.
@dhruvsakariya31292 жыл бұрын
perfect example of 32byte and 64 byte difference thank you very much sir
@mikestock18486 ай бұрын
Awesome explanation, thanks for sharing
@priyaj99084 жыл бұрын
Very useful video...Thank you sir.please try to put more videos in advanced c topics..
@rajmishra67695 жыл бұрын
Thanks for the wonderful explanation.
@comradepeter873 жыл бұрын
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.
@excite2362 жыл бұрын
Have you tried enabling optimizations with your compiler?
@あまね-y6t4 жыл бұрын
really easy to understand for me. thanks a lot!!
@pranavkshirsagar1464 жыл бұрын
Barney Stinson was their... I got so happy after seeing him😆😆
@rakurame69903 жыл бұрын
Good explanation on structure padding
@aashishmalhotra Жыл бұрын
I'm wondering why bloody YT algo doesn't recommend your channel in first year.
@Siva-fl1sq11 ай бұрын
Same feeling..
@Vishall0001811 ай бұрын
Also*
@kryptoniangaming60827 ай бұрын
Maybe they haven't done the right SEO
@elchurisrivarna2 ай бұрын
Same
@Learnwithme12eАй бұрын
Becuz first you get all indian yt channel . And becuz this channel is international so it take time to search or scroll more and u I'll get .. but when you enter on this or other channel . KZbin algorithm catch your data and next time when you search any topic it gives you the channel you visit more 👍 Or it also depending on views system
@y_red_gold_a42803 жыл бұрын
Best explanation of the concept. Thank you so much.
@Aabara_ka_dabara Жыл бұрын
something unique and new things I have learned💕💕
@vijaykounsalye5 жыл бұрын
just awesome bro you have explained very well
@jishankhan66863 жыл бұрын
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.
@premithagoni8634 Жыл бұрын
Awesome Explanation sir,Thank you
@leepakshiyadav16432 жыл бұрын
crystal clear explanation, thanks a lot :)
@RozgarBharatIT Жыл бұрын
Great Explanation!!
@multivalfran2 жыл бұрын
Excellent video my friend
@adithyay3284 жыл бұрын
Good, clear explanation!
@mudassar20122 жыл бұрын
very helpful video.....so good explanation
@donythomas72 жыл бұрын
Excellent explanation 👍
@vishnu54664 жыл бұрын
Very Interesting!...
@mdkamrankhan40325 жыл бұрын
Great explanation Sir..
@tanmayghosh83112 жыл бұрын
never thought we can optimize our code using this methods
@avronilbanerjee53022 жыл бұрын
excellent explanation
@amandarash1355 жыл бұрын
Best explanation
@rohiths-k2d Жыл бұрын
excellent lecture i have ever seen
@revan76002 жыл бұрын
Very nice explanation thank you
@nileshpokale8623 жыл бұрын
Excellent Explanation. All cleared
@haripriyaraja18903 жыл бұрын
Nice clarification 😍
@gurlinkanaveenkumar72092 жыл бұрын
Tqu sir.
@ahmedsiraj27584 жыл бұрын
when declaring 3 char, it should give 4 as output, why giving 3
@jayaprakashthokala6404 жыл бұрын
Word size is nothing but highest size of a data type used...
@anandg40184 жыл бұрын
because 3 char are taking 3 bytes of size within the word, and word is actually 4 bytes long thats why it is showing 4 bytes as output
@ImtiazAhmedRatul4 жыл бұрын
The reason behind is is that all 3 chars can be accessed using 1 CPU cycle. In other words, for CPU to access char 1 will only take 1 cycle, char 2 will take 1 cycle and char 3 will take 1 cycle. Padding is introduced to save CPU cycles. Since there is no way to get fewer cycles than 1, the compiler doesn't introduce any padding. I understand your confusion. If the CPU is accessing 1 word (4 bytes) at a time, the struct should be char (1 byte + 3 padding) x 3 = 12 bytes in size. What word size the machine will use depends on the type of data it is trying to access. So if it's trying to access a char, it is using word size == 1byte. For int, it will use 4 bytes. When it sees a structure that has both, it will use the highest size (int == 4 in the video's case). In your case, it's using 1 byte for word size.
@0mer8703 жыл бұрын
@@ImtiazAhmedRatul It seems you misunderstood his logic. He didn't say it should allocate 12 bytes but 4 which is the word size for a 32 bit processor. And since the instructor said that the processor reads one word at a time and not 1 byte, you'd except it to be always so even if it was just a char it should get allocated 4 bytes as in "1 word at a time". Therefore I think that padding applies only when the size of the variable exceeds the size of a word.
@lawalayodeji40443 жыл бұрын
The null character \0 is 1 byte. It is always at the end of all char or int.
@harshalgarg11493 жыл бұрын
Great explanation.
@chandumadhumanthi99834 жыл бұрын
Excellent👍
@shreyasingh2223 жыл бұрын
Thank you so much for detailed explanation.....
@yashikagoyal3668 ай бұрын
It means if processor is of 64 bit Then size of the discussed structure will be 8 irrespective of the order.
@mohamedmaged29775 жыл бұрын
If the size of the variable is double , this means it will take 8 byte how padding will threat with it . it can not access it at the same time because word is equal to 4 bytes !
@sudeepgour97584 жыл бұрын
It will take double as a word size and make room for 8 Byte every time. if we take char ,int ,int *,than int , guesses the size of struct now char,int, int, int *,and int now guess again .
@mamtaCoder5 жыл бұрын
Thank you sir...😃😇
@anjani_tiwari Жыл бұрын
Dhanyavaad🙏
@Jose_T1312 жыл бұрын
Very well explained, thank you sir
@somasekhardakala26305 жыл бұрын
very nice explained....thank you sir 🤝.....
@KrupaPrarthana11 ай бұрын
Wonderful ❤
@learnprogam4 жыл бұрын
You forget one point. In C programming structure have not any object. struct ABC A; here A is a variable of type struct ABC.
@botelhocpp2 жыл бұрын
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?
@mykun87372 жыл бұрын
thanks
@aps_2693 жыл бұрын
Amazing, 😍😍
@Cat_Sterling4 жыл бұрын
That was just great! I was wondering about that for so long! But what is a "word" in computer architecture?
@zidanegimiga81803 жыл бұрын
A word must be 4 or 8 bytes long, depending on the computer architecture I guess.
@47-6F-644 жыл бұрын
Amazing
@garapatianushadevi34273 жыл бұрын
Very good, just loved it
@kunalsoni76815 жыл бұрын
wow great one presentation sir..
@JohnDoe-kj2cs4 жыл бұрын
Silky smooth!
@AlokSingh-jw8fr3 жыл бұрын
struct abc { char b; int c; char a; double e; }x; Why it's output is 24? It should be 20 as per the concept sir has taught
@riyajoseph92613 жыл бұрын
Hii, as the size of double is 8, word size will be taken as 8. So, for this, it'll be 1(char) + 4(int) + 3(padding) + 1(char) + 7(padding) + 8(double). That'll give the output as 24.
@AlokSingh-jw8fr3 жыл бұрын
@@riyajoseph9261 Thanks ma'am
@luhem_3 жыл бұрын
@@riyajoseph9261 I don't think word size will be taken as 8 ...
@luhem_3 жыл бұрын
@@AlokSingh-jw8fr it should be like this : For 32 bit system -> char b(1byte) + padding (3bytes)+int c(4bytes)+char a(1byte)+padding(3bytes)+double e(4 + 4 bytes) = 20 bytes .
@fidalgoverde4 жыл бұрын
Excellent job
@nikhilwagh1728 Жыл бұрын
Great video
@shauryakumar2229 Жыл бұрын
Very helpful thanku
@somuseth4 жыл бұрын
4:40 Sir, does it mean that total of 3 cyles are required to access the 3 variables???
@kumard-n9m4 жыл бұрын
Yes
@bharatbs71414 жыл бұрын
Very Helpfull...Thank You :)
@yemreekinci10 ай бұрын
Adamsın kral çok güzel anlattın.
@093raselrahman43 жыл бұрын
Nothing to say ! Very easy explanation.
@liangzhang17224 жыл бұрын
Life saving! Ty
@yashikagoyal3668 ай бұрын
Also size of struct is not fixed. It varies with the processor.
@winxkin60563 жыл бұрын
it is very helpful
@kirankumarkakileti28114 жыл бұрын
Awsome xplanation😍
@thienphucnguyenpham69443 жыл бұрын
i think it would be better with CC ^^
@rosako4 жыл бұрын
Instead of padding and wasting memory, why not just change the order to : struct abc{int b; char a; char c}?
@yahyaaouledamer14662 жыл бұрын
amazing thanks so much
@EmpowerKnowledge00 Жыл бұрын
Please answer, #include Struct abc{ Int a; Char b; Int c; }var; Void main() { Printf("%d bytes", sizeof(var)); } Output : 12 bytes Whereas i am expecting the output to be "16 bytes" [4bytes(for a)+1bytes(for b)+3bytes(padding)+4bytes(for c)+4bytes(padding)] coz my system is of 64bit and word size has to be of 8bytes.
@ayushgemini23 күн бұрын
Although you are using 64-bit system but check the compiler specs it must be compiling for 32-bit. So (4)+(1+3)+(4) = 12 gcc -v command in cmd will tell you compiler specs
@FraPiz2 жыл бұрын
wow, my mind is blown
@preciouslife12122 жыл бұрын
thank you so much
@ElifArslan-l9g3 жыл бұрын
thank you
@andyprem3 жыл бұрын
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 ;)
@vamshimedishetty56244 жыл бұрын
Gud explanation. Sir I have a doubt. If we declare 1000 character type data type(for eg: char a1,a2,...... a1000;) the 32 bit processor makes 1000 cycles each cycle taking of 4 bytes. As per you, memory wastage is 3000 bytes. Here, allocated memory for 1000 characters is 1000 and wasted memory is 3000 bytes. Is my answer right?
@pradhanan94133 жыл бұрын
No, you're wrong
@patricktomchacko19093 жыл бұрын
The CPU makes 250 cycles in 32 bit processor, because every cycle has 4 bytes, 250*4=1000 bytes. Why will there be any wastage, characters are declared contiguously and they take 1 byte each, so they will take 1000 bytes consecutively without leaving 3 empty cells after each character.