Structure Padding in C

Sdílet
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

Komentáře • 255

  • @ahamd19
    @ahamd19 Před 4 lety +94

    speachless!! you are soooo goood in explainging. thanks a lot

  • @John-sl5zz
    @John-sl5zz Před rokem +9

    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.

  • @WistrelChianti
    @WistrelChianti Před 3 lety +19

    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).

  • @andresvallelisboa5511
    @andresvallelisboa5511 Před 4 lety +9

    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.

  • @devugoel8698
    @devugoel8698 Před rokem +12

    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!

    • @user-vy8py5ux9f
      @user-vy8py5ux9f Před rokem +2

      I couldn't agree with you more , It's awesome how he explained it.

  • @anshhmehta
    @anshhmehta Před 2 lety +5

    Perfect video to understand the importance of padding and its uses.

  • @nguyenxuannghia8089
    @nguyenxuannghia8089 Před 3 lety +17

    Thanks God ! Your video saves my embedded programming career

  • @manoharbompella418
    @manoharbompella418 Před 3 lety +3

    Explained very detailed, Cleared every doubt.
    Thank you

  • @adeshgaikwad2192
    @adeshgaikwad2192 Před 4 lety +2

    Thank you sir for clearing the concept in such an easy way...

  • @TechnoVisionTV
    @TechnoVisionTV Před rokem +1

    Such an amazing explanation! You made it so simple to understand, thank you :)

  • @mcbotface
    @mcbotface Před 4 lety +3

    Thank you sir. Keep posting more on stacks, queues, linked lists

  • @santanacasas1
    @santanacasas1 Před 2 lety

    Excellent explanation, thanks for your dedicated time in creating these videos. Regards from Mexico.

  • @rajmishra6769
    @rajmishra6769 Před 4 lety +2

    Thanks for the wonderful explanation.

  • @michaelhernandez2075
    @michaelhernandez2075 Před rokem +2

    trying to read how this works is way harder than having pictures and someone explaining. Thank you.

  • @bendono
    @bendono Před 10 měsíci +2

    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.

  • @manuelconte2127
    @manuelconte2127 Před rokem +3

    It is a good habit to put first the biggest type in ascending order to help compilator !

  • @vijaykounsalye
    @vijaykounsalye Před 4 lety +1

    just awesome bro you have explained very well

  • @user-yc2ry2uz4h
    @user-yc2ry2uz4h Před 4 lety +2

    really easy to understand for me. thanks a lot!!

  • @y_red_gold_a4280
    @y_red_gold_a4280 Před 2 lety

    Best explanation of the concept. Thank you so much.

  • @sunilkumarreddy6537
    @sunilkumarreddy6537 Před 4 lety +4

    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.

  • @leepakshiyadav1643
    @leepakshiyadav1643 Před 2 lety +1

    crystal clear explanation, thanks a lot :)

  • @ronnieahabwomugisha5283
    @ronnieahabwomugisha5283 Před 4 lety +3

    its has been clear. thanks Sir

  • @kunalsoni7681
    @kunalsoni7681 Před 4 lety

    wow great one presentation sir..

  • @priyaj9908
    @priyaj9908 Před 4 lety +1

    Very useful video...Thank you sir.please try to put more videos in advanced c topics..

  • @pnuema1.618
    @pnuema1.618 Před 2 lety

    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!

  • @adithyay328
    @adithyay328 Před 4 lety +1

    Good, clear explanation!

  • @nishantraj5020
    @nishantraj5020 Před 4 lety +1

    you make every concept so easyyyyyyyyy.

  • @mdkamrankhan4032
    @mdkamrankhan4032 Před 4 lety +1

    Great explanation Sir..

  • @shreyasingh222
    @shreyasingh222 Před 3 lety

    Thank you so much for detailed explanation.....

  • @ArjanvanVught
    @ArjanvanVught Před 4 lety +13

    Missing to explain __attribute__((packed)) with unaligned memory access which is possible (with ARM).

  • @gandhijainamgunvantkumar6783

    Amazing explanation. Thank you 😃

  • @Aabara_ka_dabara
    @Aabara_ka_dabara Před rokem

    something unique and new things I have learned💕💕

  • @05_abhisheksharma13
    @05_abhisheksharma13 Před 3 lety +1

    Amazing initiative by neso academy

  • @RozgarBharatIT
    @RozgarBharatIT Před 7 měsíci

    Great Explanation!!

  • @mikestock1848
    @mikestock1848 Před 16 dny

    Awesome explanation, thanks for sharing

  • @nileshpokale862
    @nileshpokale862 Před 3 lety

    Excellent Explanation. All cleared

  • @garapatianushadevi3427

    Very good, just loved it

  • @dakalasomasekhar6426
    @dakalasomasekhar6426 Před 4 lety

    very nice explained....thank you sir 🤝.....

  • @liangzhang1722
    @liangzhang1722 Před 4 lety +1

    Life saving! Ty

  • @premithagoni8634
    @premithagoni8634 Před rokem

    Awesome Explanation sir,Thank you

  • @mudassar2012
    @mudassar2012 Před 2 lety

    very helpful video.....so good explanation

  • @bharatbs7141
    @bharatbs7141 Před 4 lety

    Very Helpfull...Thank You :)

  • @harshalgarg1149
    @harshalgarg1149 Před 3 lety

    Great explanation.

  • @vishnu5466
    @vishnu5466 Před 3 lety +1

    Very Interesting!...

  • @charlielin188
    @charlielin188 Před 4 lety

    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

  • @psicopatico00
    @psicopatico00 Před 7 měsíci

    Well explained, thank you so much

  • @nikhilwagh1728
    @nikhilwagh1728 Před rokem

    Great video

  • @multivalfran
    @multivalfran Před rokem

    Excellent video my friend

  • @fidalgoverde
    @fidalgoverde Před 3 lety

    Excellent job

  • @47-6F-64
    @47-6F-64 Před 3 lety +2

    Amazing

  • @absorpheus
    @absorpheus Před 5 dny

    Very well explained. Thanks!

  • @sapnapatil02
    @sapnapatil02 Před 6 měsíci

    amazing!

  • @Jose_T131
    @Jose_T131 Před 2 lety

    Very well explained, thank you sir

  • @assassinhitman
    @assassinhitman Před rokem

    Amazing explanation

  • @user-si9qz3kx9h
    @user-si9qz3kx9h Před rokem

    excellent lecture i have ever seen

  • @donythomas7
    @donythomas7 Před 2 lety

    Excellent explanation 👍

  • @yahyaaouledamer1466
    @yahyaaouledamer1466 Před 2 lety

    amazing thanks so much

  • @chandumadhumanthi9983
    @chandumadhumanthi9983 Před 4 lety +1

    Excellent👍

  • @kirankumarkakileti2811

    Awsome xplanation😍

  • @amandarash135
    @amandarash135 Před 4 lety +1

    Best explanation

  • @QuratulainAzhar
    @QuratulainAzhar Před 3 měsíci +1

    Amazing 🤩

  • @avronilbanerjee5302
    @avronilbanerjee5302 Před 2 lety

    excellent explanation

  • @19n05k83
    @19n05k83 Před 2 lety +1

    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.

  • @revan7600
    @revan7600 Před 2 lety

    Very nice explanation thank you

  • @mowafkmha4505
    @mowafkmha4505 Před 2 lety

    wow bro just thank you

  • @oneblackpanda
    @oneblackpanda Před 4 měsíci

    Amazing...

  • @ሰውመሆን
    @ሰውመሆን Před rokem

    thank you so much

  • @mamtaCoder
    @mamtaCoder Před 4 lety +1

    Thank you sir...😃😇

  • @KrupaPrarthana
    @KrupaPrarthana Před 5 měsíci

    Wonderful ❤

  • @KRGAMAING
    @KRGAMAING Před rokem

    thx for the super nice video

  • @veggiefoodadventure
    @veggiefoodadventure Před 3 lety

    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

  • @aps_269
    @aps_269 Před 3 lety

    Amazing, 😍😍

  • @JohnDoe-kj2cs
    @JohnDoe-kj2cs Před 3 lety +1

    Silky smooth!

  • @andyprem
    @andyprem Před 3 lety

    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 ;)

  • @gurlinkanaveenkumar7209
    @gurlinkanaveenkumar7209 Před 2 lety +1

    Tqu sir.

  • @haripriyaraja1890
    @haripriyaraja1890 Před 2 lety

    Nice clarification 😍

  • @krishnavenimeghavath7962

    Tq so much bro

  • @shauryakumar2229
    @shauryakumar2229 Před rokem

    Very helpful thanku

  • @winxkin6056
    @winxkin6056 Před 2 lety

    it is very helpful

  • @rakurame6990
    @rakurame6990 Před 2 lety

    Good explanation on structure padding

  • @user-bu8mg7uq3s
    @user-bu8mg7uq3s Před 3 lety

    thank you

  • @anjani_tiwari
    @anjani_tiwari Před 10 měsíci

    Dhanyavaad🙏

  • @RahulRazj
    @RahulRazj Před 3 lety +2

    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?

  • @silentcat4292
    @silentcat4292 Před 4 lety

    Crystal clear

  • @jishankhan6686
    @jishankhan6686 Před 2 lety

    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.

  • @krishnakumar-kh5vo
    @krishnakumar-kh5vo Před 2 lety

    well explained

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz Před 2 lety +4

    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.

    • @excite236
      @excite236 Před rokem

      Have you tried enabling optimizations with your compiler?

  • @sujitsatpute3741
    @sujitsatpute3741 Před 3 lety +5

    You are explaining 💯 times better than my college professor......

    • @SJ_46
      @SJ_46 Před rokem +1

      1000 bro

  • @01GNZ
    @01GNZ Před 3 lety

    Is this applicable for type declarations in main function?

  • @kiranmk2385
    @kiranmk2385 Před 2 lety

    Very nice

  • @mykun8737
    @mykun8737 Před 2 lety

    thanks

  • @sandeepnaikoti7700
    @sandeepnaikoti7700 Před 3 lety

    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;

  • @botelhocpp
    @botelhocpp Před 2 lety

    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?

  • @andistheinforitbutso7513
    @andistheinforitbutso7513 Před 2 lety +3

    Awesome work 👏
    Lesson: we should be careful while arranging the srruct variables for better memory utilisation

    • @pnuema1.618
      @pnuema1.618 Před 2 lety +1

      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.

  • @vipulchawla5466
    @vipulchawla5466 Před 4 lety +2

    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???

    • @kumargaurav8234
      @kumargaurav8234 Před 4 lety +1

      Because double is 8 bytes long, so the word size would be 8 bytes long. Hence 8*3 = 24 bytes

    • @HarshitSharma-kq5yi
      @HarshitSharma-kq5yi Před 4 lety +1

      @@kumargaurav8234 your reply cleared every doubt i had thanks

  • @beeyou6220
    @beeyou6220 Před 2 lety +1

    I m having 8 yrs of experience. Noone Clarified the doubt lk u..thank you..expecting more content from you

  • @sohitgore2924
    @sohitgore2924 Před 2 lety

    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

  • @RAVITEJAP-ss9rl
    @RAVITEJAP-ss9rl Před 3 lety +1

    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....

  • @purubhargava8096
    @purubhargava8096 Před 3 lety

    bhaot hard sirjee

  • @rokeyabegum139
    @rokeyabegum139 Před 3 lety

    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 ?