Dynamic Arrays in C

65,307
0
2024-01-21に共有

コメント (21)
  • There is a slight oversight here relating to data alignment. If the data type requires a larger alignment than that of the platforms' pointer, then the data in the array will be misaligned. This could result in either a performance penalty or an exception. I'm not much of a C programmer, so I'm unsure of a completely portable solution but as of C11 you can use _Alignof to figure out how much patting to add to the header. It would also be good to allow a user to manually specify sticter alignments, incase they want to do something like declare an array of a certain type but plan to apply vector operations to it which require stricter alignment.
  • Coming fresh off of reading the K&R book on C, This is a very informative and entertaining video. Great stuff
  • Today I learned that “unordered remove” is a thing that I feel i should’ve known a long time ago.
  • @whym1here
    I use to implement the vector by 1st method in uni. I will try to implement the 2nd method as it seems nicer to me. Thanks for teaching new stuff. Hopping for more videos on complex data structures such as hash tables and balanced binary search tree in future (in C obviously 🙂).
  • @g0mnster296
    i beg you to make a beginner-intermediate C tutorial, you are really good at explaining things.
  • @ryanc674
    is there any command that i can use to show the profiles of two programs at 2:56
  • @kumboi
    Sick video! I learned a lot
  • Amazing video Sir! Agree with the other comment: please make a beginner-intemediate C tutorial. Or if you don't have the time to make a full series, then I would be very happy with these kinds of videos ~ C lang tips and tricks Cheers!
  • @mythacker4365
    Thanks. Besides all debate happening in comment section, I learned something today. That's good 😊.
  • C makes it feel like moving structs around in memory would just be a matter of (uint8_t*) casting and moving the bytes, sadly this isn't always the case for most architectures.
  • @rickperez8975
    Wow C is such a versatile language, I see why other languages are built on it
  • @haotj
    Does this handle alignment of T? What will happen if alignof(T) is bigger than alignof(Array_Header)?
  • @jintz2
    Thanks for sharing! Love your C videos!
  • @Illogical.
    Is there a way to reserve a bunch of memory, and have labels that point to various places in the reserved memory? Example: label_a might point to the first slot in the reserved memory, label_a[7] points to the eightth slot in that reserved section of memory, but maybe label_b points to the sixth slot in reserved memory.
  • @pushqrdx
    Is there a name for the color scheme you're using in this video? I find it very easy on my eyes and wish I can use it for code.
  • @johanngerell
    The second version doesn't handle reallocation. If the client has a pointer to the array data (that comes after the header) and reallocation is needed (assuming that functionality exists), then the client must be told to update his variable to the new array data. Therefore, version 2 is a great solution for fixed length arrays - for instance immutable string types. Passing out "a header" is necessary when the referenced array data can be reallocated - then the client doesn't need to know when reallocations happen.
  • What are you using to make such videos. i.e. what software is that were you click around to minimize / maximize topics/headings.
  • The thing is with object oriented code I don't think comparing line count is a valid way to determine what compile time should be.