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.
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 :/
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
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.
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 :/
this is one of best c/cpp vectors tutorial
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.
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++
Eso es lo que le falta a tu canal de CZcams, algo desde lo básico y de ahí pasar a tus cursos
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. ;-)
I recently started learning about vectors and I found this vid really helpful
Ótima explicação, parabéns!
maravilhoso!
Thank you, this is very useful.
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.
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.
What about, if T doesn't have constructor? new T[2 * n] throws errror
Thanks a lot. It makes sense now. What do you suggest me if I decide to my own implement of stack and queue?
Great video!
а зачем float? например 320х240 разрешение предполагает что нам не нужны знаки после запятой. или я что то недопонял?
Great content as always. Keep up the great work... ps your paid courses are amazing!
Nice explaination
Great! Thank you Gustavo!
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!
What font are you using in your IDE
Hi Gustavo, do you have a video about socket programming using c++?
Very good !!! thanks!
Awsome! Do you have the dotfiles of your vi setup that you can share? Thanks
vim pelo akita, gostei muito do canal parabéns.
Grande Danilo! Obrigado.
Seu canal parece muito legal o Akita indicou e estou gostando
Vim pelo Akita! Já inscrito no canal!
Grande Pablo! Abraços.
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. 🙂
Eu reconheço o sotaque brasileiro quando eu escuto
Me descobriram! 😅
what font do you use?
IBM's Code Page 437
@@pikuma thank you!!
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++;
}
this person is cool af
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.
The internet needs to know what you are drinking in this crazy glass!
chimarrão
Claaaaro! ❤️🙂🇧🇷
Devia criar conteúdo em português em 👀 ( se já tiver ignora kkk) vim pelo Akita
Great video!