title
Arrays in C++

description
Patreon ► https://patreon.com/thecherno Twitter ► https://twitter.com/thecherno Instagram ► https://instagram.com/thecherno Slack ► https://slack.thecherno.com Pointers ► https://youtu.be/DTxHyVn0ODg Debugging ► https://youtu.be/0ebzPwixrJA Series Playlist ► https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb Gear I use: ----------------- BEST laptop for programming! ► http://geni.us/pakTES My FAVOURITE keyboard for programming! ► http://geni.us/zNhB FAVOURITE monitors for programming! ► http://geni.us/Ig6KBq MAIN Camera ► http://geni.us/t6xyDRO MAIN Lens ► http://geni.us/xGoDWT Second Camera ► http://geni.us/CYUQ Microphone ► http://geni.us/wqO6g7K

detail
{'title': 'Arrays in C++', 'heatmap': [{'end': 544.725, 'start': 521.335, 'weight': 0.763}, {'end': 693.04, 'start': 643.542, 'weight': 0.841}, {'end': 762.348, 'start': 739.836, 'weight': 0.714}, {'end': 1045.378, 'start': 1021.01, 'weight': 0.725}], 'summary': 'Covers the basics and manipulation of arrays in c++, emphasizing the significance of understanding pointers and potential memory access violations, discussing the efficiency and memory allocation involved in array manipulation using for loops, and highlighting the memory allocation, performance impact, and safety considerations when using arrays in c++ 11.', 'chapters': [{'end': 278.757, 'segs': [{'end': 50.46, 'src': 'embed', 'start': 16.082, 'weight': 0, 'content': [{'end': 17.843, 'text': 'I made an entire video based on pointers.', 'start': 16.082, 'duration': 1.761}, {'end': 20.405, 'text': 'There will be a card on the screen or a link in the description below.', 'start': 17.863, 'duration': 2.542}, {'end': 22.407, 'text': 'Definitely check that out first before this video.', 'start': 20.465, 'duration': 1.942}, {'end': 26.39, 'text': 'Pointers are pretty much the basis for how arrays work in C++, so you definitely need to understand that.', 'start': 22.527, 'duration': 3.863}, {'end': 30.432, 'text': 'So first of all, what is an array? An array is basically a collection of elements.', 'start': 26.59, 'duration': 3.842}, {'end': 32.873, 'text': "It's a bunch of things in a particular order.", 'start': 30.592, 'duration': 2.281}, {'end': 37.855, 'text': 'In our case, in C++, an array is basically a way to represent a collection of variables.', 'start': 33.033, 'duration': 4.822}, {'end': 41.896, 'text': "It's basically a bunch of variables, usually of the same type, in a row.", 'start': 37.895, 'duration': 4.001}, {'end': 49.099, 'text': 'The reason this is so important and so useful is because there are countless times where we want to be able to represent a whole collection of data,', 'start': 42.076, 'duration': 7.023}, {'end': 50.46, 'text': 'a whole bunch of data.', 'start': 49.099, 'duration': 1.361}], 'summary': 'Video focuses on pointers and arrays in c++, emphasizing their importance in representing collections of variables.', 'duration': 34.378, 'max_score': 16.082, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU16082.jpg'}, {'end': 133.349, 'src': 'embed', 'start': 103.124, 'weight': 4, 'content': [{'end': 108.967, 'text': 'we give an array, a single name, and through that we can refer to as many variables as we created the array with.', 'start': 103.124, 'duration': 5.843}, {'end': 110.367, 'text': "let's dive into some code and take a look.", 'start': 108.967, 'duration': 1.4}, {'end': 112.088, 'text': 'so defining an array is quite simple.', 'start': 110.367, 'duration': 1.721}, {'end': 114.35, 'text': 'suppose that i wanted an array of five integers.', 'start': 112.088, 'duration': 2.262}, {'end': 116.531, 'text': 'i would simply write the type that i want the array of.', 'start': 114.35, 'duration': 2.181}, {'end': 122.457, 'text': 'I would then give it a name, for example, example, and then in square brackets, I put how many I want.', 'start': 117.131, 'duration': 5.326}, {'end': 124.559, 'text': "so we'll just say five, and that's it.", 'start': 122.457, 'duration': 2.102}, {'end': 126.742, 'text': 'I now have an array of five integers.', 'start': 124.559, 'duration': 2.183}, {'end': 133.349, 'text': "I've basically allocated enough space to store five integers now in order to actually set and access those integers.", 'start': 126.742, 'duration': 6.607}], 'summary': "Defining an array is simple - specify type, name, and size. for example, an array of five integers is created in square brackets, named 'example'.", 'duration': 30.225, 'max_score': 103.124, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU103124.jpg'}, {'end': 275.674, 'src': 'embed', 'start': 246.266, 'weight': 3, 'content': [{'end': 251.81, 'text': "Now it's really important that you actually be careful with this and make sure that you're always writing inside the bounds of the array,", 'start': 246.266, 'duration': 5.544}, {'end': 259.154, 'text': "because if you're not, it can cause problems that can be fairly difficult to debug because you've just modified memory that wasn't part of this array,", 'start': 251.81, 'duration': 7.344}, {'end': 262.517, 'text': 'however, might be part of another variable in your source code.', 'start': 259.154, 'duration': 3.363}, {'end': 269.971, 'text': "So you've just literally gone ahead and changed some other variable in your code to something else without realizing it.", 'start': 263.017, 'duration': 6.954}, {'end': 275.674, 'text': "So just make sure that you set up safety checks where needed to make sure that you're not riding outside of the bounds.", 'start': 270.251, 'duration': 5.423}], 'summary': 'Ensure writing within array bounds to avoid memory issues and unintended variable changes.', 'duration': 29.408, 'max_score': 246.266, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU246266.jpg'}], 'start': 0.069, 'title': 'Basics of arrays in c++', 'summary': 'Covers the significance of using arrays in c++ to store and access multiple variables of the same type, highlighting the importance of understanding pointers and the potential memory access violations if not used carefully.', 'chapters': [{'end': 50.46, 'start': 0.069, 'title': 'C++ arrays basics', 'summary': 'Covers the basics of arrays in c++, emphasizing the importance of understanding pointers, and explains that an array is a collection of variables of the same type, used to represent a whole collection of data.', 'duration': 50.391, 'highlights': ['An array in C++ is a way to represent a collection of variables, usually of the same type, in a row, and understanding pointers is crucial as they form the basis for how arrays work.', 'The importance and usefulness of arrays lie in their ability to represent a whole collection of data, which is particularly valuable in various scenarios.']}, {'end': 278.757, 'start': 50.76, 'title': 'Array basics in c++', 'summary': 'Explains the significance of using arrays in c++ to store and access multiple variables of the same type, providing a more efficient and maintainable solution compared to creating individual variables, with the possibility of causing memory access violations if not used carefully.', 'duration': 227.997, 'highlights': ['Arrays allow grouping of variables, providing a more efficient and maintainable solution. Using arrays in C++ allows for the grouping of variables of the same type, providing a more efficient and maintainable solution compared to creating individual variables.', 'Memory access violations can occur if accessing elements outside the array bounds, causing potential debugging challenges. Accessing elements outside the bounds of the array can cause memory access violations, leading to potential debugging challenges and the risk of modifying memory belonging to other variables.', 'Arrays offer a simpler and more manageable way to store and access multiple variables of the same type. Arrays provide a simpler and more manageable way to store and access multiple variables of the same type, eliminating the need to manually create and name individual variables.']}], 'duration': 278.688, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU69.jpg', 'highlights': ['Understanding pointers is crucial as they form the basis for how arrays work.', 'The importance and usefulness of arrays lie in their ability to represent a whole collection of data.', 'Using arrays in C++ allows for the grouping of variables of the same type, providing a more efficient and maintainable solution compared to creating individual variables.', 'Accessing elements outside the bounds of the array can cause memory access violations, leading to potential debugging challenges and the risk of modifying memory belonging to other variables.', 'Arrays provide a simpler and more manageable way to store and access multiple variables of the same type, eliminating the need to manually create and name individual variables.']}, {'end': 554.332, 'segs': [{'end': 307.88, 'src': 'embed', 'start': 278.977, 'weight': 0, 'content': [{'end': 286.462, 'text': 'Now, arrays go really well with for loops, because for loops are indexable loops that go through a particular range right?', 'start': 278.977, 'duration': 7.485}, {'end': 292.085, 'text': 'So if we wanted to set every single value inside our example, array a for loop is a really good way of achieving this.', 'start': 286.782, 'duration': 5.303}, {'end': 296.809, 'text': 'Without a for loop, we would have to go through all of these indices and actually set them manually.', 'start': 292.466, 'duration': 4.343}, {'end': 299.811, 'text': "and that's how we would achieve setting everything to 2.", 'start': 297.589, 'duration': 2.222}, {'end': 307.88, 'text': 'However, by creating a for loop that goes through the entire length of our array, which is 5, and simply sets example at i equal to 2,,', 'start': 299.811, 'duration': 8.069}], 'summary': 'Using a for loop to set all values in an array to 2, with array length of 5.', 'duration': 28.903, 'max_score': 278.977, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU278977.jpg'}, {'end': 340.82, 'src': 'embed', 'start': 313.345, 'weight': 4, 'content': [{'end': 319.308, 'text': 'Since index four is the last point at which i is less than five, we could have also written less than or equal to four.', 'start': 313.345, 'duration': 5.963}, {'end': 321.73, 'text': 'However, no one really writes code like this.', 'start': 319.368, 'duration': 2.362}, {'end': 326.392, 'text': "And also it'll be a bit of a performance hit because you're doing a less than and equals comparison.", 'start': 321.83, 'duration': 4.562}, {'end': 329.434, 'text': 'So it has to do that equals comparison instead of just a less than comparison.', 'start': 326.412, 'duration': 3.022}, {'end': 334.417, 'text': "So it's almost always written as less than five instead of less than or equal to four.", 'start': 329.594, 'duration': 4.823}, {'end': 340.82, 'text': 'If we run this code now, just put breakpoint on our cn.get, we can take a look at what this actually looks like in our memory.', 'start': 335.177, 'duration': 5.643}], 'summary': "Using 'less than five' is preferred due to performance reasons, as it avoids the additional equals comparison.", 'duration': 27.475, 'max_score': 313.345, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU313345.jpg'}, {'end': 390.054, 'src': 'embed', 'start': 361.973, 'weight': 2, 'content': [{'end': 368.499, 'text': 'So one of the really important thing about arrays is that they store their data contiguously, which means they saw their data in a row.', 'start': 361.973, 'duration': 6.526}, {'end': 373.903, 'text': "So I've allocated space for five integers, meaning I'm literally going to get one integer after the other in memory.", 'start': 368.639, 'duration': 5.264}, {'end': 375.585, 'text': 'Each integer is four bytes.', 'start': 374.384, 'duration': 1.201}, {'end': 378.267, 'text': "So what I've got here is 20 bytes worth of memory.", 'start': 375.725, 'duration': 2.542}, {'end': 383.89, 'text': 'in a row, which is divided into kind of four byte segments, not really divided into four byte segments.', 'start': 378.687, 'duration': 5.203}, {'end': 390.054, 'text': 'However, when we access it through our code and all that, it is, for all intents and purposes, divided into four byte segments,', 'start': 384.23, 'duration': 5.824}], 'summary': 'Arrays store data contiguously, 5 integers allocated with 20 bytes of memory, each integer is 4 bytes.', 'duration': 28.081, 'max_score': 361.973, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU361973.jpg'}, {'end': 458.351, 'src': 'embed', 'start': 432.819, 'weight': 3, 'content': [{'end': 438.105, 'text': 'So if we write a value to example at index two, it will write to that portion of memory.', 'start': 432.819, 'duration': 5.286}, {'end': 441.326, 'text': 'Now as I mentioned, an array is really just a pointer.', 'start': 438.405, 'duration': 2.921}, {'end': 446.787, 'text': "It's an integer pointer in this case to that block of memory which contains our five integers.", 'start': 441.826, 'duration': 4.961}, {'end': 453.069, 'text': 'Which means that I can actually create a variable here which is just an integer pointer and give it the value of example.', 'start': 446.967, 'duration': 6.102}, {'end': 455.71, 'text': 'And you can see that works fine and that will compile just fine.', 'start': 453.169, 'duration': 2.541}, {'end': 458.351, 'text': 'because example is just an integer pointer.', 'start': 455.97, 'duration': 2.381}], 'summary': 'An array is a pointer to a block of memory containing five integers.', 'duration': 25.532, 'max_score': 432.819, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU432819.jpg'}, {'end': 544.725, 'src': 'heatmap', 'start': 521.335, 'weight': 0.763, 'content': [{'end': 528.243, 'text': 'If I wanted to actually deal with bytes, I could cast this pointer to a data type that is, just one byte large, for example a char, and then,', 'start': 521.335, 'duration': 6.908}, {'end': 531.587, 'text': "if I do that, I'll have to add on the eight bytes that I talked about.", 'start': 528.243, 'duration': 3.344}, {'end': 536.915, 'text': 'then want to write in an integer which is four bytes, not just a single char which is one byte.', 'start': 532.268, 'duration': 4.647}, {'end': 542.102, 'text': 'once i actually do the plus eight, i would need to cast this back into an integer pointer and then, of course,', 'start': 536.915, 'duration': 5.187}, {'end': 544.725, 'text': 'dereference it to get my integer so that i can set it equal to six.', 'start': 542.102, 'duration': 2.623}], 'summary': 'Manipulate bytes by casting pointer to char and adding 8 bytes to write an integer.', 'duration': 23.39, 'max_score': 521.335, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU521335.jpg'}], 'start': 278.977, 'title': 'Array manipulation in c++', 'summary': 'Discusses using for loops to iterate through arrays and the efficiency it offers, as well as the memory allocation and pointer arithmetic involved in accessing array elements in c++.', 'chapters': [{'end': 313.345, 'start': 278.977, 'title': 'Using for loops with arrays', 'summary': 'Explains how for loops can be used to iterate through arrays, with a specific example of setting every value inside an array to 2 using a for loop, which is more efficient than setting them manually.', 'duration': 34.368, 'highlights': ['Using for loops with arrays allows for efficient iteration through the entire array, as demonstrated by setting every value inside an array to 2 using a for loop, which is more efficient than setting them manually.', 'For loops are indexable loops that can go through a particular range, and by creating a for loop that goes through the entire length of the array, which is 5 in this example, every value inside the array can be set efficiently.']}, {'end': 554.332, 'start': 313.345, 'title': 'Array memory allocation in c++', 'summary': 'Explains how arrays store data contiguously, the pointer arithmetic involved in accessing array elements, and the impact of using less than or equal to and less than in code, including a demonstration of rewriting code using pointer arithmetic.', 'duration': 240.987, 'highlights': ['Arrays store data contiguously, with each integer occupying 4 bytes, resulting in 20 bytes of memory for 5 integers. The arrays store their data contiguously, meaning they store their data in a row, with 5 integers occupying 20 bytes of memory, each integer being 4 bytes.', 'Explanation of pointer arithmetic involved in accessing array elements and setting their values. The chapter explains the pointer arithmetic involved in accessing array elements, such as adding an offset of 8 bytes to access the third element in the array, and setting it to a different value using simple pointer arithmetic.', 'Impact of using less than or equal to and less than in code, with less than being the preferred choice due to performance considerations. The chapter discusses the impact of using less than or equal to and less than in code, highlighting that less than is almost always preferred due to performance considerations, as the former incurs a performance hit by doing an equals comparison in addition to a less than comparison.']}], 'duration': 275.355, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU278977.jpg', 'highlights': ['Using for loops with arrays allows for efficient iteration through the entire array, as demonstrated by setting every value inside an array to 2 using a for loop, which is more efficient than setting them manually.', 'For loops are indexable loops that can go through a particular range, and by creating a for loop that goes through the entire length of the array, which is 5 in this example, every value inside the array can be set efficiently.', 'Arrays store data contiguously, with each integer occupying 4 bytes, resulting in 20 bytes of memory for 5 integers.', 'Explanation of pointer arithmetic involved in accessing array elements and setting their values.', 'Impact of using less than or equal to and less than in code, with less than being the preferred choice due to performance considerations.']}, {'end': 1093.955, 'segs': [{'end': 579.547, 'src': 'embed', 'start': 554.672, 'weight': 2, 'content': [{'end': 561.395, 'text': 'So yes, you can get pretty fancy with this, but essentially what I wrote here is exactly what this indexing does.', 'start': 554.672, 'duration': 6.723}, {'end': 562.235, 'text': "It's not magic.", 'start': 561.435, 'duration': 0.8}, {'end': 563.315, 'text': "That's how arrays work.", 'start': 562.355, 'duration': 0.96}, {'end': 570.959, 'text': "They're just a contiguous block of data and you can literally index them like they were a book and write to a specific page or, in this case,", 'start': 563.355, 'duration': 7.604}, {'end': 571.799, 'text': 'a specific integer.', 'start': 570.959, 'duration': 0.84}, {'end': 577.064, 'text': "Now, we're gonna wrap this up here pretty soon because I don't wanna get too in-depth into arrays and confuse you.", 'start': 572.079, 'duration': 4.985}, {'end': 579.547, 'text': 'However, you can also create arrays on the heap.', 'start': 577.165, 'duration': 2.382}], 'summary': 'Arrays are contiguous data blocks; can be indexed to access specific elements.', 'duration': 24.875, 'max_score': 554.672, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU554672.jpg'}, {'end': 693.04, 'src': 'heatmap', 'start': 643.542, 'weight': 0.841, 'content': [{'end': 648.184, 'text': "Of course I could have written this in a single for loop, Let's hit F5.", 'start': 643.542, 'duration': 4.642}, {'end': 651.766, 'text': 'So if I type an example over here in my view, I get my five twos in a row.', 'start': 648.424, 'duration': 3.342}, {'end': 655.528, 'text': "And of course, if I type in another, I'm also going to get the exact same result.", 'start': 652.146, 'duration': 3.382}, {'end': 659.651, 'text': 'So why would you allocate dynamically, using the new keyword, rather than just creating it on the stack?', 'start': 655.708, 'duration': 3.943}, {'end': 663.453, 'text': 'The biggest example is to do with lifetimes, right?', 'start': 659.791, 'duration': 3.662}, {'end': 666.895, 'text': 'Because, like anything that you allocate with new, it will be around until you delete it.', 'start': 663.533, 'duration': 3.362}, {'end': 672.238, 'text': 'So if you have a function returning a new array, for example, you have to allocate it using a new keyword,', 'start': 666.915, 'duration': 5.323}, {'end': 676.181, 'text': 'unless you pass in a memory address via the parameter or something like that.', 'start': 672.238, 'duration': 3.943}, {'end': 682.608, 'text': "if you want to actually return an array and it's a brand new array that was created inside the function, you need to use the new keyword.", 'start': 676.861, 'duration': 5.747}, {'end': 685.451, 'text': 'Another thing to think about though is memory indirection.', 'start': 682.748, 'duration': 2.703}, {'end': 688.375, 'text': "Basically, what I mean by that is, since we're actually holding a pointer,", 'start': 685.511, 'duration': 2.864}, {'end': 693.04, 'text': 'that pointer is going to point to another block of memory which holds our actual array,', 'start': 688.375, 'duration': 4.665}], 'summary': "Using 'new' for dynamic allocation ensures memory persistence and enables array return in functions.", 'duration': 49.498, 'max_score': 643.542, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU643542.jpg'}, {'end': 693.04, 'src': 'embed', 'start': 663.533, 'weight': 0, 'content': [{'end': 666.895, 'text': 'Because, like anything that you allocate with new, it will be around until you delete it.', 'start': 663.533, 'duration': 3.362}, {'end': 672.238, 'text': 'So if you have a function returning a new array, for example, you have to allocate it using a new keyword,', 'start': 666.915, 'duration': 5.323}, {'end': 676.181, 'text': 'unless you pass in a memory address via the parameter or something like that.', 'start': 672.238, 'duration': 3.943}, {'end': 682.608, 'text': "if you want to actually return an array and it's a brand new array that was created inside the function, you need to use the new keyword.", 'start': 676.861, 'duration': 5.747}, {'end': 685.451, 'text': 'Another thing to think about though is memory indirection.', 'start': 682.748, 'duration': 2.703}, {'end': 688.375, 'text': "Basically, what I mean by that is, since we're actually holding a pointer,", 'start': 685.511, 'duration': 2.864}, {'end': 693.04, 'text': 'that pointer is going to point to another block of memory which holds our actual array,', 'start': 688.375, 'duration': 4.665}], 'summary': "Using 'new' for allocating new arrays in functions ensures memory allocation until deletion.", 'duration': 29.507, 'max_score': 663.533, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU663533.jpg'}, {'end': 767.77, 'src': 'heatmap', 'start': 739.836, 'weight': 0.714, 'content': [{'end': 744.898, 'text': "You can see that if I go to the memory address of my entity, I don't see my twos there at all.", 'start': 739.836, 'duration': 5.062}, {'end': 748.12, 'text': 'I see this other memory address, which of course is this pointer.', 'start': 745.118, 'duration': 3.002}, {'end': 749.8, 'text': 'Now I can copy this and put it here.', 'start': 748.48, 'duration': 1.32}, {'end': 751.942, 'text': "I'll have to reverse it because of the NDNS though.", 'start': 749.841, 'duration': 2.101}, {'end': 753.522, 'text': 'So this will actually be 007D5E.', 'start': 751.962, 'duration': 1.56}, {'end': 760.487, 'text': 'and hit Enter, I get taken to my actual data.', 'start': 757.205, 'duration': 3.282}, {'end': 762.348, 'text': "So there's that indirection again.", 'start': 760.947, 'duration': 1.401}, {'end': 767.77, 'text': "We've actually got the memory address of E, which contains another memory address, to where our actual array is,", 'start': 762.888, 'duration': 4.882}], 'summary': 'Discussion on memory addresses and indirection with quantifiable data.', 'duration': 27.934, 'max_score': 739.836, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU739836.jpg'}, {'end': 796.829, 'src': 'embed', 'start': 767.77, 'weight': 4, 'content': [{'end': 773.293, 'text': "which means that when we want to access this, we're basically jumping all around our code, first to get to the entity,", 'start': 767.77, 'duration': 5.523}, {'end': 775.715, 'text': 'then to get to the array All of that stuff.', 'start': 773.293, 'duration': 2.422}, {'end': 779.117, 'text': 'So, of course, whenever possible, you want to create your array on the stack to avoid that,', 'start': 775.735, 'duration': 3.382}, {'end': 782.719, 'text': 'because jumping around memory like that is definitely a performance hit.', 'start': 779.117, 'duration': 3.602}, {'end': 784.481, 'text': "Now, there's one more thing I want to mention.", 'start': 782.779, 'duration': 1.702}, {'end': 785.782, 'text': 'I know this is a huge video.', 'start': 784.521, 'duration': 1.261}, {'end': 789.104, 'text': 'I hope you guys like these kind of massive videos and you have time to watch them.', 'start': 785.802, 'duration': 3.302}, {'end': 792.246, 'text': 'But I want to mention arrays in C++ 11.', 'start': 789.264, 'duration': 2.982}, {'end': 796.829, 'text': "In C++ 11, we've got something called standard array, which is an actual inbuilt data structure.", 'start': 792.246, 'duration': 4.583}], 'summary': 'Creating arrays on the stack in c++ 11 improves performance by avoiding jumping around memory.', 'duration': 29.059, 'max_score': 767.77, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU767770.jpg'}, {'end': 825.612, 'src': 'embed', 'start': 799.611, 'weight': 1, 'content': [{'end': 804.695, 'text': "A lot of people really like using it over the raw array that I've shown you here because it offers a number of advantages.", 'start': 799.611, 'duration': 5.084}, {'end': 809.579, 'text': 'namely being that it includes bounds checking and it actually keeps track of the size of our array.', 'start': 805.195, 'duration': 4.384}, {'end': 813.862, 'text': "One more thing that I didn't mention is that there's actually no way to work out the size of our array.", 'start': 809.679, 'duration': 4.183}, {'end': 818.426, 'text': "If we allocate an array on the heap like this, we've specified it to be five,", 'start': 814.162, 'duration': 4.264}, {'end': 823.87, 'text': 'and in many other languages we can actually write something like example.size.', 'start': 818.426, 'duration': 5.444}, {'end': 825.612, 'text': "You can't do that in C++.", 'start': 824.291, 'duration': 1.321}], 'summary': 'Preferred over raw array for bounds checking and size tracking in c++.', 'duration': 26.001, 'max_score': 799.611, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU799611.jpg'}, {'end': 958.969, 'src': 'embed', 'start': 933.875, 'weight': 5, 'content': [{'end': 940.299, 'text': "And of course, as soon as you decide to pass this into a function or anything, it becomes an int pointer and then you're just, you're screwed.", 'start': 933.875, 'duration': 6.424}, {'end': 943.602, 'text': 'So what you have to do instead is actually just maintain that size by yourself.', 'start': 940.419, 'duration': 3.183}, {'end': 947.504, 'text': "I know it kind of sucks in that sense, but it's just, that's just how C++ works.", 'start': 943.702, 'duration': 3.802}, {'end': 948.865, 'text': 'You have to maintain it yourself.', 'start': 947.524, 'duration': 1.341}, {'end': 955.988, 'text': 'The way that I would write this code personally is I would declare a constant size to be five, and then I would put this in here.', 'start': 948.985, 'duration': 7.003}, {'end': 958.969, 'text': "Now I love that this gives us an error because you can't actually do that.", 'start': 956.088, 'duration': 2.881}], 'summary': 'In c++, maintaining the size of int pointers manually is necessary; declaring a constant size of five for better error management.', 'duration': 25.094, 'max_score': 933.875, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU933875.jpg'}, {'end': 1047.9, 'src': 'heatmap', 'start': 1021.01, 'weight': 0.725, 'content': [{'end': 1024.33, 'text': 'if we put an angular bracket here, it says we need the type name and the size.', 'start': 1021.01, 'duration': 3.32}, {'end': 1028.973, 'text': "so we'll write int as the type, comma five as the size, and that's it.", 'start': 1024.33, 'duration': 4.643}, {'end': 1035.115, 'text': "we've created this array and to fill it up, of course we can actually do another dot size, and there we go, we have five,", 'start': 1028.973, 'duration': 6.142}, {'end': 1036.395, 'text': "so it's an easier way to deal with this.", 'start': 1035.115, 'duration': 1.28}, {'end': 1040.837, 'text': 'of course it does have the overhead, because It does all of the balance checking if you want it to.', 'start': 1036.395, 'duration': 4.442}, {'end': 1045.378, 'text': 'And also it actually maintains a size integer as well, which you might not want.', 'start': 1041.156, 'duration': 4.222}, {'end': 1046.74, 'text': 'So there is a bit of overhead.', 'start': 1045.719, 'duration': 1.021}, {'end': 1047.9, 'text': "Usually it's worth it.", 'start': 1047.14, 'duration': 0.76}], 'summary': 'Creating an array with type int and size 5, with some overhead for balance checking and maintaining a size integer.', 'duration': 26.89, 'max_score': 1021.01, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU1021010.jpg'}], 'start': 554.672, 'title': 'Arrays, memory allocation, and performance impact in c++ 11', 'summary': 'Covers the concept of arrays, their allocation on stack and heap, the use of new keyword for dynamic allocation, and the implications on lifetime and memory indirection. it also discusses the performance impact of accessing arrays, introduces standard arrays in c++ 11 with built-in bounds checking and size tracking, and emphasizes the need to maintain array size manually when using raw arrays in c++, advising on using standard arrays for safer use.', 'chapters': [{'end': 767.77, 'start': 554.672, 'title': 'Arrays and memory allocation', 'summary': 'Explains the concept of arrays, their allocation on stack and heap, including the use of new keyword for dynamic allocation, and the implications on lifetime and memory indirection.', 'duration': 213.098, 'highlights': ['Arrays can be indexed like a book, allowing data to be written to specific locations, and can be allocated on the stack or heap, with the latter requiring manual deletion, impacting their lifetime.', 'Dynamic allocation using the new keyword is essential for returning a new array from a function and dealing with memory indirection, which can lead to memory fragmentation and cache misses in complex scenarios.', 'Creating arrays on the heap involves memory indirection, with the pointer pointing to another block of memory containing the actual array, leading to differences in memory addresses and access.']}, {'end': 1093.955, 'start': 767.77, 'title': 'C++ 11 arrays and memory allocation', 'summary': 'Discusses the performance impact of accessing arrays, introduces standard arrays in c++ 11 with built-in bounds checking and size tracking, and emphasizes the need to maintain array size manually when using raw arrays in c++, advising on using standard arrays for safer use.', 'duration': 326.185, 'highlights': ['Standard array in C++ 11 offers built-in bounds checking and size tracking The chapter introduces standard arrays in C++ 11, highlighting its advantages over raw arrays, such as built-in bounds checking and maintaining the size of the array, offering a safer alternative for array usage.', 'Performance impact of accessing arrays in C++ The chapter emphasizes the performance hit of accessing arrays, particularly when jumping around memory, and advises creating arrays on the stack to avoid performance degradation.', "Importance of maintaining array size manually in C++ It's highlighted that in C++, there's no direct way to work out the size of an array, and it's crucial to manually maintain the size when using raw arrays to avoid potential issues and errors."]}], 'duration': 539.283, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/ENDaJi08jCU/pics/ENDaJi08jCU554672.jpg', 'highlights': ['Dynamic allocation using new keyword is essential for returning a new array from a function and dealing with memory indirection, which can lead to memory fragmentation and cache misses in complex scenarios.', 'Standard array in C++ 11 offers built-in bounds checking and size tracking, providing a safer alternative for array usage.', 'Arrays can be indexed like a book, allowing data to be written to specific locations, and can be allocated on the stack or heap, with the latter requiring manual deletion, impacting their lifetime.', 'Creating arrays on the heap involves memory indirection, with the pointer pointing to another block of memory containing the actual array, leading to differences in memory addresses and access.', 'The chapter emphasizes the performance hit of accessing arrays, particularly when jumping around memory, and advises creating arrays on the stack to avoid performance degradation.', "Importance of maintaining array size manually in C++ is highlighted, as there's no direct way to work out the size of an array, and it's crucial to manually maintain the size when using raw arrays to avoid potential issues and errors."]}], 'highlights': ['Understanding pointers is crucial as they form the basis for how arrays work.', 'The importance and usefulness of arrays lie in their ability to represent a whole collection of data.', 'Using arrays in C++ allows for the grouping of variables of the same type, providing a more efficient and maintainable solution compared to creating individual variables.', 'Accessing elements outside the bounds of the array can cause memory access violations, leading to potential debugging challenges and the risk of modifying memory belonging to other variables.', 'Arrays provide a simpler and more manageable way to store and access multiple variables of the same type, eliminating the need to manually create and name individual variables.', 'Using for loops with arrays allows for efficient iteration through the entire array, as demonstrated by setting every value inside an array to 2 using a for loop, which is more efficient than setting them manually.', 'For loops are indexable loops that can go through a particular range, and by creating a for loop that goes through the entire length of the array, which is 5 in this example, every value inside the array can be set efficiently.', 'Arrays store data contiguously, with each integer occupying 4 bytes, resulting in 20 bytes of memory for 5 integers.', 'Dynamic allocation using new keyword is essential for returning a new array from a function and dealing with memory indirection, which can lead to memory fragmentation and cache misses in complex scenarios.', 'Standard array in C++ 11 offers built-in bounds checking and size tracking, providing a safer alternative for array usage.', 'Arrays can be indexed like a book, allowing data to be written to specific locations, and can be allocated on the stack or heap, with the latter requiring manual deletion, impacting their lifetime.', "Importance of maintaining array size manually in C++ is highlighted, as there's no direct way to work out the size of an array, and it's crucial to manually maintain the size when using raw arrays to avoid potential issues and errors."]}