Video není dostupné.
Omlouváme se.
Dynamic Arrays in C++ (std::vector)
Vložit
- čas přidán 7. 08. 2024
- Patreon ► / thecherno
Twitter ► / thecherno
Instagram ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/cpp
Why is it called "vector"? ► stackoverflow.com/questions/5...
EASTL ► github.com/electronicarts/EASTL
Thank you to the following Patreon supporters:
- Samuel Egger
- Dominic Pace
Gear I use:
-----------------
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/t6xyDRO
MAIN Lens ► geni.us/xGoDWT
Second Camera ► geni.us/CYUQ
Microphone ► geni.us/wqO6g7K
I love how you treat C++ like an actual language you'd speak in
He explains it in such a clear way!
Great set of videos!
I study computer engineering, and work with C++ for nearly all assignments. When there's issues with the code, I've been using these videos to get a deeper understanding on how a certain topic works, and it's been a huge help. Keep it up!
your videos are truly amazing. I wasn't able to catch up at first but now i really enjoy it and i am getting to understand more and more about c++ everyday
Brilliant channel man! Right now I have to implement an algorithm in an efficient way in C++ for my studies, your videos are an incredible help!
It will be so cool to compare one of the STL container (as an example) with one rewritten in the EA library and see the differences ;)
it will be 35$ extra for that DLC
better not to, BF2042 is one reason for that, game so broken that Engine so broken as well and plus extra charge for DLC, so good that Cherno left EA
@@Blonder_Studio he's too good, passionate and professional for them.
Man i'm so glad I found your channel, you're saving me rn
Fantastic channel! So great to get things explained by someone who actually knows what goes on behind the scenes, and who does not make absolutely everything into an programming analogy with food and animals.
10/10
Seriously, you are better than my instructors at explaining everything. You are better at explaining than the damn books. These trimmed down and non bloated explanations are so much better than what I have been going through.
I learned more watching this than a week taking my CSII course! Keep it up
Same
Thank you! One of the best YT channels to explain simply difficult (at first glance) problems and especially put them into practice
So much usefull information,u do not just give general understanding of a topic but provide the logic of its work
i am glad i found your channel
Go boy, go! You're my inspiration for learning C++. Your videos and your charisma and attitude!
I double this. He's not like most of the other people that teach this stuff on youtube. Listening to most people is like listening to text to speech or Ben stein and watching pain dry at the same time. This guy will make my life if he avoids using the word GOOEY and says G U I like a normal human being.
@@MrSerozka Sure, they make up something that sounds retarded and takes more to spell than the original spelling for... reasons! Fuckin millennials..
I wonder after 4 years if you ever did learn c++.
@@mrbrian826 Yes, but I still don't use it as my primary language, practically for anything... I'm into C# at the moment
@@ytacctaccnt nice
I learned a lot , thanks
pls keep it up and make some video about graph representation and boost library
Great stuff! The name confused me too when I first learned about std::vector..
Great video.
I learn so much from this guy. real talent.
I would like to learn more about the best practices of memory allocation.
Up to this point it's not that I don't know all these, it's just I want to see how you program, because you have way better programming style than I did. Thanks Cherno!
Thanks for putting so much effort into these videos.
Wow that was pretty well done. I think I got enough to try out my own sort of mini project.
Amazing channel, just found it. :) Also the first tutorial channel I have ever found that I do not listen to at 1.5X speed.
i need to slow it down sometimes i think lol
11:34
Roughly speaking, abstract thinking develops over the years as a programmer which is a good trait so one doesn't have to stay longer into details like this.
Probably my favorite programming channel, Not only are his videos exciting, his style is so much cleaner. Best channel on youtube!
Yea he tends to dig a bit deeper than others :)
@@jannesopanen8032 here you are replying to a comment from a couple years ago, and I've already forgotten all I knew about programming.
It's called a vector because Alex Stepanov, the designer of the Standard Template Library, was looking for a name to distinguish it from built-in arrays. He admits now that he made a mistake, because mathematics already uses the term 'vector' for a fixed-length sequence of numbers. C++11 compounds this mistake by introducing a class 'array' that behaves similarly to a mathematical vector.
Alex's lesson: be very careful every time you name something.
So now we have a class named Vector that behaves kinda like an array and a class named array that behaves kinda like a vector...
Indeed, be careful when naming something
Thank you SO SO SO MUCH BROOO! You don't know how you've just helped me... I understood every single thing you just said.😱👍👍👍
This is amazing, man. I like your videos so much
Yepp...
I was also confused with going from Unity C# vectors...
To the C++ version of vectors! XD
Nice video!
Very nicely explained and very informative!
very nice little class learned so much cheers!
Thanks The Cherno! Great explanation as always! 👍
Subscribed! Looking forward to going over your videos on C++👍👍👍👍👍
11:30 Thanks for addressing this finally... Coming from C# I saw the method signatures in C++ and thought "are humans supposed to be able to read this"
you are amazing at teaching, keep it up!
it happened again. Near the end of the video, I thought someone else was playing music somewhere until i realized the source coming from this video...
Great video as always!
Thanks a lot......clearly explained basics about vector(Dynamic Array or Array List)👏👏👏
Quality content! Thumbs up!
Thank You For Saving My Semester :)
Very nice , Please make more videos on other data structures
Is it bad that instead of watching the video I'm just watching his hands?
No
explains pretty much everything
If I'm watching his hands, it's because he's getting close to backhanding the cactus.
That is the purpose of the video. The hand gestures are an advanced form of hypnosis that will make you understand vectors better.
I think The Cherno is secretly Italian ;)
at 9:48 if anyone doesn't understand how he initialized the struct you can search for "aggregate initialization".
great content !
bro, you're too smart! goddamn, good shit
"Simple spice series" very accurate caption
You should mention emplace_back in another video.
hey, what do you use to program in c++? Visual Studio? Awsome work ^^
11:40 C++ is love♥️
你好,陈诺,你的课讲的太好了
Good video !!!
How we should use inline ?
if function are short we should use inline otherwise we shouldn't ?
please make parallel process and simd tutorial
Man, your concepts are so clear.
You're a god with a compiler. Been programming in C++ for longer than I care to admit, and when I stumble across something I'm not 100% confident with I think "I wonder if Cherno can help me out here" and sure enough you can, and have, several times! Keep up the good work bud, VERY much appreciated.
Nice video ; I'm really confused of these vectors in computer science if we needed a dynamic array we would use a linked list .
what is the difference between these two ?
To think I was modestly learning about pointers and jumped into this rabbit hole.
how do you access vectors of vectors? like in an matrix cause you can't exactly do matrix.assign() to a specific value can you?
Good job
does it basically work like dynamic memory allocation with malloc/realloc in c?
Can you recommend a book or course that gets more in depth information about behind the scenes of c++?
how can we make the function for import series data (around 5000points)?
hi could you tell us how to watch a bool vector in debug time?. because l did it for int and strings without problems
Nice video bud.
Excellent!
Will be glad to see someone trying to rewrite a STL written thing which can be more optimal and more towards the personal use case.
I have a question not related to the topic, why are classes in the standard library defined with lowercase identifiers, even though everyone declares classes with camel casing?
I absolutely love the comparison with Java, because I started out with Java in High School.
learning programmin in high school sucks balls
i learned c# in high school and my "teacher" is a piece of shit bad
How do you init a vector with values, not push after ?
Coding and guitar
That's an awesome combo!
Can i use the vectors for struct with different data types
Whats the difference between dynamic array and vector ? are they both the same thing ?
hey cherno, why dont you use "using namespace std" when you code?
I remember in Bjarne Stroustrup's book, he never talks about raw array, he just went a head and talks about std::vector.
Hm... While following along after making the Vertex class and attempting to print it to the console using
std::cout
If i have a pointer to a vector which then moves to a different memory address to due to resize does my pointer automatically point to the new memory address?
so i didnt know how the vector class worked, so i created an "ArrayList" class,
and i did the exact same thing that the vector class does xD to add an element just create a new array with current size + 1 and copy all of the previous contents into array[0 to size-1] and put the new element into array[size]
@Peterolen i know but it is sort of a simplified version of the vector and ArrayList. It has the same concept behind it
I know this is about five years later, but another reason I've learned not to store pointers in vectors is that the element can be deleted from the vector leaving a memory leak. If you're using vectors with pointers, be careful.
Yes, you are great!
your ccoding skill are great!
I envy you!
I tried casting an int to (std::vector::const_iterator) to use as argument for the erase function, to no avail. Anyone understand what happens when vertices.begin + 1 is used as an argument? It seems there is some conversion going on, right? Why can the '1' be used there without any problem?
what happens if there are no vertex does not have parameters would it just be vertices.empalce_back() ?
At 8:50 there's a note about moving rather than copying. Is there a video about this in this series?
All the videos have in common that when you made a question and the answer is: "It depends"
Thanks
I tried to do this thing for like 4 hours in total, and now i learned there is library that does this. (wasn't able to do it btw, i got stuck on some exceptions and shit)
Can you do something similar in C or just the classic memory allocation commands?
Also, if I know the amount that I'm going to insert but it's defined by the user is it correct to declare the array like "Arr[nAmount]"?
@Peterolen yes, I know about them. The problem is that not every c compiler accepts the example I wrote in the second paragraph. In some microchips you simply can't give variable length, only memory commands.
Good video, but if you have a vector of string, what can you do if you want the first character of a string?
hello, I have a code which is working for the existing hardware setup but now I want to extend this code for mutiple hardware at a time. for this type of project. can anyone guide me on this this.
Awesome.
Yet to understand why my professor decided to teach so much array stuff but said “vectors are the same so I’m gonna skip over them” when in reality, these vectors are beautiful works of art that shit on arrays lol. Simply the fact that they’re dynamic makes life so easy.
In physics we can represent a vector as a row or column matrix( kinda like a 1d array ).
maybe that's why
Please make a video on STL in C++
In linear algebra pne of the basic example of vectors is exactly what programmer would think of as an array or a tuple. So mathematically its quite natural to identify arrays and vectors as being very similar, if not the same thing
kindly can someone tell me where is the AISTL link
Enough eye contact for today
What about dynamic arrays using pointers?
But is it dynamic?
I am having confusion with it!
Plz. Ans
I thought that arrays were pointers, so that you are never really passing the array to the function, but only the pointer, so you wouldn't need to pass by reference. Is it different for dynamic arrays, or am I misunderstanding something?
Dynamic arrays (mostly std::vector) is an array which can resize. You can push new things into it.
Hey Cherno!
I got a little question about passing the vector to a subfunction:
In the Video at about 12:50 you are passing the vector via Function(vertices);
I would have expected a Function(vertices&); to specify it as a pointer or a reference, basically.
In C, every array is automatically passed by reference, it will never be copied.
Is it in C++ depending on the parameters of the target function as it is a pointer in your example?
Would love to hear your answer as I am a C developer and sometimes C++ is still a little strange to me.
All the best!
Personal Notes:
-dynamic size, at the background it has limited memory but when reaches the limit, it creates a bigger sized memory and copies contents to it.
- #include
- std::vector vertices
To add: entities.push_back((1,0,0)) (must be implicit conversion)
- can use it in for loop:
for(Vertex v: vertices) { //do sth }
To prevent copying and being faster,
for(Vertex& v: vertices) { //do sth }
- to delete 2nd element: vertices.erase(vertices.begin()+1)
I was writing a little game in c as a bit of a challenge and I had to write my own dynamic array. The way I did it was that you create it with an initial size, but when it exceeds the size, the size of the array doubles. That way I don't have to reallocate the array every single time I add or remove an element, but I'm also not using up too much memory.
I'm pretty sure that is what vectors do as well.
11.11 what kind of for loop that is?
THE Best !
i love you papi cherno