Thanks for this video! I'm currently taking your C++ 2D Game Engine course, and took this detour to better understand the Vector class, since I'm coming from a web development background where everything is much more abstracted. I made an insert implementation as follow: void Insert(int index, T value){ //Handle the case where we're already at the max size before inserting if(size == capacity){ T* newArray = new T[capacity * 2]; for (int i = 0; i < size; i++){ newArray[i] = elements[i]; } delete[] elements; elements = newArray; capacity *= 2; } //Increase the size by 1 size++; //Loop over the array in reverse, setting each value equal to the one before, stopping at the given index for(int i = size - 1; i >= index; i--){ elements[i + 1] = elements[i]; } //Replace the given index with the given value elements[index] = value; } It's basic and there might be some edge cases I overlooked, but it seems to work from my testing.
Wow your knowledge about this is so deep. I'm trying to develop my skill and knowledge in programming as I'm a beginner in it. I've started C++ because some people said it's the hardest to learn so I thought why not? I like learning hard stuff but theres way too much in C++
I love how you kept the memories of the classic retro games alive. Good stuff! :) So, vector and C++ can work for console like NES? If so, that's really cool!
Dear Professor Pezzi Thanks for the video! Very well explained! If I wanted to do something like this in C. What do I have to pay attention to, besides checking whether there is enough memory (malloc). Are there things that I absolutely have to do? (You talked about the whole thing not being so trivial).
Good question! We have to use a similar idea, but allocate using malloc(), reallocating/doubling size when necessary using realloc(), and freeing resources with free(). To achieve some sort of "generic" type handling with your dynamic array (for example, being able to create and manipulate different types), we could take advantage of void* and use macros to resolve the type dynamically at compile time. Thse repos are good examples of a simple dynamic array implementation in C99 using the ideas I mentioned above. github.com/eignnx/dynarray github.com/gustavopezzi/dynamicarray
The title made me think this would be an in-depth look at the machinations of how the standard library's vector _really_ works, but this is a very basic introduction. Your element-removals do not even call any potential destructor :/
Thanks for this video! I'm currently taking your C++ 2D Game Engine course, and took this detour to better understand the Vector class, since I'm coming from a web development background where everything is much more abstracted. I made an insert implementation as follow:
void Insert(int index, T value){
//Handle the case where we're already at the max size before inserting
if(size == capacity){
T* newArray = new T[capacity * 2];
for (int i = 0; i < size; i++){
newArray[i] = elements[i];
}
delete[] elements;
elements = newArray;
capacity *= 2;
}
//Increase the size by 1
size++;
//Loop over the array in reverse, setting each value equal to the one before, stopping at the given index
for(int i = size - 1; i >= index; i--){
elements[i + 1] = elements[i];
}
//Replace the given index with the given value
elements[index] = value;
}
It's basic and there might be some edge cases I overlooked, but it seems to work from my testing.
this is one of best c/cpp vectors tutorial
One more follower. I came through @Akitando channel. Very nice explanation.
Welcome aboard! Abraços!!! :)
@@pikuma and please accept Akita's defy to choose 3 linux distros. ;-)
Wow your knowledge about this is so deep. I'm trying to develop my skill and knowledge in programming as I'm a beginner in it. I've started C++ because some people said it's the hardest to learn so I thought why not? I like learning hard stuff but theres way too much in C++
I recently started learning about vectors and I found this vid really helpful
Eso es lo que le falta a tu canal de RUclips, algo desde lo básico y de ahí pasar a tus cursos
I really should've found your youtube channel earlier. I'm doing your assembly language course on udemy too. You are a very good teacher.
i cant belive your channel just have 10k subscribers, your videos are so good!!
I love how you kept the memories of the classic retro games alive.
Good stuff! :)
So, vector and C++ can work for console like NES? If so, that's really cool!
There are many homebrew games developed in C.
Every single one of your videos is awesome. Thank you!
tu é lindão em ..... vim pelo akita
Grande Akita! :) Abração e obrigado pelo comment.
Thanks a lot. It makes sense now. What do you suggest me if I decide to my own implement of stack and queue?
Ótima explicação, parabéns!
maravilhoso!
Great content as always. Keep up the great work... ps your paid courses are amazing!
Dear Professor Pezzi
Thanks for the video! Very well explained!
If I wanted to do something like this in C. What do I have to pay attention to, besides checking whether there is enough memory (malloc). Are there things that I absolutely have to do? (You talked about the whole thing not being so trivial).
Good question!
We have to use a similar idea, but allocate using malloc(), reallocating/doubling size when necessary using realloc(), and freeing resources with free().
To achieve some sort of "generic" type handling with your dynamic array (for example, being able to create and manipulate different types), we could take advantage of void* and use macros to resolve the type dynamically at compile time.
Thse repos are good examples of a simple dynamic array implementation in C99 using the ideas I mentioned above.
github.com/eignnx/dynarray
github.com/gustavopezzi/dynamicarray
@@pikuma Very good, thanks for the advice and sources. I'll be happy to look at that!
Vim pelo Akita! Já inscrito no canal!
Grande Pablo! Abraços.
Nice explaination
The title made me think this would be an in-depth look at the machinations of how the standard library's vector _really_ works, but this is a very basic introduction. Your element-removals do not even call any potential destructor :/
Thank you, this is very useful.
Awsome! Do you have the dotfiles of your vi setup that you can share? Thanks
Hi Gustavo, do you have a video about socket programming using c++?
37:28 in lines 23 why it had a lot of const? first const and last const?
Great video!
Great! Thank you Gustavo!
What about, if T doesn't have constructor? new T[2 * n] throws errror
vim pelo akita, gostei muito do canal parabéns.
Grande Danilo! Obrigado.
а зачем float? например 320х240 разрешение предполагает что нам не нужны знаки после запятой. или я что то недопонял?
Seu canal parece muito legal o Akita indicou e estou gostando
Parabéns xirú. Não conhecia teu canal, acabei chegando aqui pelo Akita. Muito bom. Inscrito e fortalecendo a comunidade.
Opa James, obrigado! Um grande quebra costela. 🙂
What font are you using in your IDE
Very good !!! thanks!
this person is cool af
void Insert(int index, T value){
if (size == capacity){
T* newarr = new T[capacity*2];
for (int i = 0; i index; i--)
{
elements[i] = elements[i-1];
}
elements[index] = value;
size++;
}
what font do you use?
IBM's Code Page 437
@@pikuma thank you!!
The internet needs to know what you are drinking in this crazy glass!
I'm sure your first language is portuguese, are you brazilian?
yes
@@pikuma Cool, I know you didn't ask, but I'm studying Computer Engineering at UTFPR in Paraná-BR
@@lucassamuel6069 Haha. Que legal. Eu tenho vários amigos por lá. Sou do RS. 🙂
Gustavo, tenho uns cursos seus na Udemy e fiquei desconfiado quando vi um chimarrao em uma das aulas haha.
Vc é fera, ensina muito bem.
bro use typewriter for coding 💀
chimarrão
Claaaaro! ❤️🙂🇧🇷
Great video!