ARRAY - Making DATA STRUCTURES in C++
The first 1000 people who click the link will get 2 free months of Skillshare Premium: skl.sh/thechernoproject10
Patreon ► / thecherno
Instagram ► / thecherno
Twitter ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/cpp
This video was sponsored by Skillshare.
Пікірлер: 238
Thanks for watching! Don't forget that the first 1000 people who click the link will get 2 free months of Skillshare Premium: skl.sh/thechernoproject10
@swapnilbhave3767
3 жыл бұрын
Watched your all C++ vidoes.. those are awesome.. thanks for this video waiting for STL from long time
@skillerraptor8669
3 жыл бұрын
Damn I cannot take it.
@ketanlalcheta4558
3 жыл бұрын
Not able to sign up
@amirasyraf3352
3 жыл бұрын
Just wanna say thank you so much for the Skillshare offer. Can't wait to study more programming and game design! :D
@aqezzz
3 жыл бұрын
Thanks for this, I've been wanting to try it! Got in on it!
Suggestion: video on CMAKE, makefiles, etc
@kaoti
3 жыл бұрын
YES PLEASE
@jscorpio1987
3 жыл бұрын
Somebody asks that on almost every one of those videos and I’m pretty sure the reason he hasn’t done a video on the subject is because Makefiles, etc., aren’t part of the C++ language, and this is a C++ language tutorial. Plus, he uses visual studio, which doesn’t use Makefiles, so it would be pointless.
@klauseternal3381
3 жыл бұрын
@@jscorpio1987 you could say it's a null pointer
@leocarvalho8051
3 жыл бұрын
He doesnt even use cmake and makefile is not usefull to him since he uses windows+vstudio only
@deathscreton
3 жыл бұрын
Those are poor excuses for not doing it. Plenty of projects that use C++ make use of cmake or make files. He probably runs into them quite a bit, especially with open source projects.
Waiting for data structures for a looooong time super excited for this series
Love raw breakdowns like this. This quality is what makes your channel unique 👍
Awesome man! Very glad you opted to start delving into data structures and algorithms in your C++ vids! Very much looking forward to more of these! Thanks so much.
Suggestion: linked lists then binary trees. My knowledge of this area is a little patchy and hearing a second expert explanation of a topic is always welcome.
@locomotivere4497
3 жыл бұрын
cool
@nallid7357
3 жыл бұрын
I agree with this order, binary trees are in of themselves a linked list. Hopefully he'll explain doubly, single, and circular linked lists sometime soon.
@soniablanche5672
4 ай бұрын
@@nallid7357 Not all. You can implement binary heap with an array.
I'm glad you're doing this series lmao. I took a data structures course at my university last year, and now I can keep myself refreshed on the material through these videos so I don't forget all these concepts
Simply brilliant, Cherno! Keep them coming!
I've wanted to this exact thing for a long time and was never able to fit the pieces together. Thank you. :D
I was waiting soo eagerly for this 🙏🏼 your videos have become my bread butter daily these days haha. Thanks so much for sharing all your knowledge cherno!
i love you for doing this. 1 BIG recommedation is to move this videos to early parts of the playlist. many thanks. love your work!
This series is super helpfull! :) Edit: Also, the way Cherno explains the things (dissected and explained step by step, from basic functionality too the more complex results) is so much better then most written documentation you can find..
Love this data structure focused video in the C++ series. Please keep the coming!
Thanks for this series. The stack and heap allocation just made me smile.
Thank you So Much , you are the best channel i've seen ... you are beyond professional. You are my inspiration in learning c++ and, i hope you keep making videos, love you Cherno.
Thank you so much ! Looking forward for the iteraror implementation. Also, I'd like to see you talk about boost library, more specifically boost::bind methods (also also, I believe they have been integrated into STD by now)
Definitely need video on implementing iterator please
@jamesmnguyen
3 жыл бұрын
A really super simple forward iterator is literally just a pointer. So part of your goal is already done.
@oracleoftroy
3 жыл бұрын
@@jamesmnguyen Yeah, but that only works for two data structures, vector and array, and the latter works because arrays decay into pointers. Implementing iterators for anything else is more complicated.
@maksymiliank5135
3 жыл бұрын
@@oracleoftroy Iterators for linked lists are also pretty easy. It gets harder for trees though, because you need to figure out the logic to access every element in the right order. Especially if it is a search tree, where the order is important
@nashaut7635
3 жыл бұрын
@@maksymiliank5135 ... which is indeed one good reason to look forward for a tutorial from The Cherno. That promises to be quite exciting.
Waited for this for so long! Looking forward.
I'm really gonna LOVE this! I was always trying to implement different STL classes that I use and love myself. And also to expand and add upon them. My favourite ones were String and List(dynamic array). Thanks a lot for your great content Yan 💙💙
@lionkor98
3 жыл бұрын
std::list is not a dynamic array ;)
Thank you Cherno! was helpful as always.
That "noise" at the top is very useful. It allows you to write things like using container = std::array; container x; memset(x.data(), 0, x.size() * sizeof(container::value_type)); Then when you need to change int to uint64_t or uint8_t, you only need to change it in one place. Putting sizeof(int) in that memset is buffer overflow waiting to happen.
Loved your videos. Learning so much.
This was so helpful! Thanks
glad you're making data structs & algos series. would also be good to mention using arrays unless you need optimization is bad practice, and more generally optimizing before you need to. and it would be nice if you go into some of the nitty gritty details about why there's an overhead from not keeping your data contiguous; it's not self evident, and especially mysterious if you know your programs use virtual memory.
Definitely gave me more insight regarding OOP and templates!
Awesome! Can't wait to see the next DS 😍
Would love it if you would do more of these!
Love this style where the video zooms in on the code and it is easier to see.👍
Thanks, Cherno! Your channel is a real treasure)
My very favourite topic in C++ : data structures. Thank you so looking forward to it.
Thank you so much 🙂. What a great series of c++..
best cover of data structure. Thanks for sharing
I found this very useful, thank you!
Thank you Cherno. Admire your work.
Yes more of this please
Great refresher!!!♡☆
Great Video! I just made a dynamic array and a doubly linked list last semester. It is so much harder than it oringinally sounded. Would love to see how to create a (un)ordered (multi)map or a priority tree of some sort! Thanks again! :)
Nice video as always ^^ I'd like to see some implementation of Dictionaries and maybe showing that with hash functions. I only understand that they are probably used for that, but I wonder how you actually use them effective. Wondering how much space to allocate and still use hashes.
Great Great Great! video. What a great video to watch while drinking my morning coffee ;)
The content....Love it 🔥
I am an undergraduate student. I already love your content and find it really inspiring. But can you please do more content related to basics and Data Structures?
thanks for the explanation😊
Suggestion: templated version of segment tree. I know it's not that important but if you find time, it'll be pretty interesting to do.
Great videos!!! Could you make a video about UNIT TESTs in C++?
@ProttoUFSC
3 жыл бұрын
up
@AvocadoHappiness
3 жыл бұрын
Yes please!
Live demos are cool! Hopefully I will see you on some gamedev/cpp conference as a speaker.
Would love to see videos implementing data structures of other STL containers like vectors and strings with things such as iterators within them in the future. Anyway, great video :)
FINALLY!! I've been waiting for a DATA STRUCTURES series for what feels like ages. Much appreciated!!
Nice, would be lovely to see you cover tree-based data structures. probably after linked lists.
Cherno this C++ series is legendary
Very good content as always. In one of the first videos (video 2 of C++ Series) I downloaded your vs settings. They seems to have changed. Do you update the link or give a one with your updated settings?
AVL trees intrigue me and I'd love to see them in a future video
A few remarks The STL array has its underlying array field public to allow for aggregate initialization, like you can do with a plain array. All the type members like pointer, const_iterator, etc. are actually required by the standard, not just in MSVC implementation
Honestly, I did not touch c++ since 3rd year at uni. This video made ne remember a lot about c++ and tought me more about it than 2 hours at uni ever did) Def subscribed coaus of that. Even though I don't use c++ at work)
I'd love to see a simple compiler series using flex and bison to generate a abstract syntax tree that is class based. Then see it in action. An AST that can be reused in other languages you work on.
Could you do a video on ideas for projects beginners/intermediate C++ programmers could do to add on to their resume? Currently going into my 3rd year in college, and I'm looking to apply for internships for next summer, but I don't really have any projects to put on my resume nor do I know where to start.
@Terracraft321
3 жыл бұрын
How is it going
That is exactly what i want to learn.
You are running through the material so fast, you cannot be teaching. You are not teaching what you are talking about but running through the material demonstrating how well you know it. But, for someone trying to learn, it all flies over my head.
Thank you
Waiting for this
While arrays may be easy to deal with, I would certainly like to see you implement some much more complex types like tuple. XD Also, those size_type things are required by the standard, so that template meta-programming on std containers is easier. std::array are implemented as a struct containing a public member of the array, which makes the struct an aggregate, that enables the aggregate initialization syntax (like std::array array{ 0,1,2,3,4 };) without requiring any constructor to be implemented manually.
@sebastiangudino9377
Жыл бұрын
How is a tuple complex?
@ChlorieHCl
Жыл бұрын
@@sebastiangudino9377 Try implement a tuple type yourself and you'll see.
Careful with alloca(), it is non-standard (even in C) I think it's only standardized by POSIX, which makes sense because Microsoft's version easily breaks in try/catch blocks. alloca() does have its uses, but if you can get away with a stack array or a SmallVector, you probably want to use that instead.
I dislike all those who hit the dislike button. Thanks for that beautiful lesson Cherno!
thanks for the video
dude you are a god
nice & usefull video
In case you need it, here is the source code of the array data structure: #include #include template class Array{ public: constexpr size_t Size() const { return S; } T& operator[](size_t index){ return m_Data[index]; } const T& operator[](size_t index) const{ return m_Data[index]; } T* Data(){ return m_Data; } const T* Data() const { return m_Data; } private: T m_Data[S]; }; int main(){ Array data; data[0] = "Cherno"; data[1] = "C++"; data[2] = "We"; data[3] = "Love"; data[4] = "Programming!"; for(size_t i = 0; i
Thanks again
More videos like this pls pls!!!!!!!!!
Great video! Suggestion: I would really like to know what constexpr and noexcept are...
you know , I had sworn that I will never understand loops but after watching your video on the topic , I am on the safe side now, I guess, Thanks man....
Thank you for this tutorial, it was really helpful :) I have two questions about templates: 1. If the template implementation has to be in the header file, is it even possible to distribute closed-source template libaries with pre-compiled binaries? 2. If a template class is just copy-pasted by the compiler for the different template arguments, isn't this a huge waste of memory? So you save some data memory by not having to store the size of the array in a variable, but isn't this cancelled out by the fact that the whole class is copy-pasted which takes up more code memory?
@MsJavaWolf
3 жыл бұрын
1. The template definitions actually don't have to be in the header file, they just have to be in the compilation unit that uses them. You can still split it into .h and .cpp files, but in that case you have to include both the .h and the .cpp in every file that uses them. I agree that the header only variant is much cleaner though, afaik there is no way to make it closed source. 2. Yes, it also makes your executable bigger and can make your compilation times longer. However I find that, unless we are talking about embedded systems, it's not a big deal. Sometimes there is no better way to do it in c++ or any language close to the hardware imo and also keep in mind that if you use the template with the same arguments multiple times it won't get copied many times, it only gets copied when you change the template argument.
Suggestion: I know this isn't a data structure, but somewhat related. Could you talk about endianness and how to deal with it? I suppose this is more to do with data punning than anything, but as a firmware engineer working in c, it would be nice to know how one deals with it in c++.
WE WANT MORE DATA STRUCT VIDEOS les goo
What if I want put my array in function method? I don't want care about size. I want use Size()! Again, I have to use template? tamplate function doSomthing(Array arr){ ... }? So if i have hundred or thousand of diffrent arrays I have to alwase make copy of function who will do stuf? Did I miss understand it? Should I create second function to handle size ? To avoid make copy of huge block of code? Grrr... More I am thinking about it, more it become complicated.
The alloca has a larger issue there. Unrelated to performance. The problem is that it will be freed after the constructor retutn/exit the scope of the function. Meaning you can not use it like that. Only way to get around that is to make the allocation in the scope where the object is created. If you do it like you did it might compile and work in some cases. But in reality you are using stack memory that the program sees as free and might be occupied by other stuff. So it's an undefined behavior. Alloca is awesome, but dangerous if used wrong like that. Should make eha clear.
Exception handling, and whether or not to use them please :)
hey man. i have a question about skillshare. i'd like to know a bit what kinda stuff is on there without registrating becuase i don't wanna waste the 2 free months because i currently don't have a lot of time yet. so can you quickly go there and browse for dsp courses for me to inform me if there's some stuff about dsp programming? or things like filter design for audio filters
Is there a way to initialise the array class with a brace-enclosed list like you can with std::array For clarification here's an example: std::array test = { 5, 8, 6 ,8, 3}; But with my own class, I would have to initialise the array, then manually add each value, which is too inefficient.
Wow continue doing data structure please
In a case where a class constructor takes a pointer of data in parameter and stores it in a class member, I can't quite find a good way to deal with the nature of the pointer. Is there a way to tell if it was stack allocated or heap allocated? The main use case is for a class interface for users who don't exactly know how the class is implemented. If the data is stack allocated and passed to an instanced of the class which is heap allocated, the class should copy the data and delete it in its destructor. But if the data is already heap allocated copying it is a waste of performance and memory. Is there a prefered way for this kind of situation? I am missing an abvious poin?
@_destinator_
3 жыл бұрын
You should copy the object regardless of whether it is stack- or heap-allocated. Even if the data is allocated on the heap, your class is now dependend on data that it does not own. Someone else will eventually have to delete that data and you might be left with an invalid pointer. However, this could also be solved with an std::shared_ptr. The shared pointer would guarantee that the data can not be deleted while your class is still using it. The shared pointer only allows for heap-allocated objects though, so you option 1 might be your only option.
Looking forward to Cherno making his own mini-stl
@donrumata5299
3 жыл бұрын
the::cherno::libs::standard::stl
Cherno, can you please make a video to explain the difference between constexpr and const ? Thank you ...
Is there a reason the Data() function returns a pointer rather than an address like the operator[] function? I saw your references video and know they are very similar, but not sure if it matters in this case. Thanks for these awesome videos by the way!
Great!!!
Please cover unit tests and tuples implementation.
I dig arrays but it feels like whenever I'm writing a program (mind you I'm not a programmer by education or profession, I just have had some classes in my degree), it's a case where you ask the user the size of the container (or the data set to be more accurate) if you're not reading it from a file. And c++ doesn't let me get that size, then create an array with that size and use it, it demands a const size that apparently needs to be set at compiling. Although at some point I somehow managed to make it compile with the user input variable size for array size, I have no idea why. It got very upset some days later and redlined it hard. Somehow I had managed to make some sort of loophole around it. Maybe it treated it as heap allocated somehow. It would be really nice to get those turned into stack allocated arrays though, because every function used all the data in the container. Maybe if there was a good idea of the limits of the data set, but I find that the programs I've written to help with some stuff should allow quite big sets, even though I might use it for small sets especially in testing. In general, I find that most if not all of my programs revolve around asking user input and then calculating something. Programming would be so nice if it was done without user inputs. Especially Rust would be nice to use without.
Awesome! Would love to see more data structure videos :)
Hey just wondering if I can get your visual studio config in terms of colors? Hope you understand what I mean
And just a question, how do I write a constructor for the Array class, so I can do something like this: Array test_arr = {2, 4, 6}; ?
@stepanhrbek8151
3 жыл бұрын
@Artem Katerynych Yeah, thanks, now I know.
hi bro can u start the data structures and mainly algorithm series if u have time.im eagerly looking for that series. or can u point where i can learn those concepts really good.
The problem I had with these types of structures is that it becomes annoying to pass the arrays around in functions. since Array is a completely different type than Array unless there's some magical c++ way to do it...
Does anyone know which theme he uses for Visual Studio?
Awesome
A question, if I were to have many arrays of different sizes, will the class be generated for every one of them? will it slow compilation time significantly?
@ulriksndergaard5271
3 жыл бұрын
yes and yes :-)
Can't you use const for the size issue ? You said template is the only solution for that issue.
The TAs at my Data Structures class allocate *everything* in the heap, even objects which already allocate to the heap by themselves. And they don't even care about releasing the used memory before ending the program. The program may compile and run one way or the other, but I think that's a very bad habit (and bad habits die hard). At least they could tell us we shouldn't do that in production environments or something like that.
@lionkor98
3 жыл бұрын
Those people usually come from Java where you "new" everything and never delete
Would you make a video about constexpr and noexcept
We can technically define: const int size = 7; And before using it to define an array, we can change its value via a pointer like this: int c = 5; const int a(c); cin >> (*(&c + 1)); int array[a] ////////// Now I know that array size must be declared at compile time but this just works... I wonder what strange behaviours will be caused by this hmmmmm...
_malloca should be used, it is a version of alloca with security enhancements.
14:44 Why empty() always returns false in MSVC STL?
@expurple
3 жыл бұрын
I'm getting "true" from empty() on std::array with MSVC. So there's probably a different version of that function somewhere in the code, or something like that.