The NEW Keyword in C++

  Рет қаралды 242,293

The Cherno

The Cherno

Күн бұрын

Patreon ► / thecherno
Twitter ► / thecherno
Instagram ► / thecherno
Discord ► / discord
How to create objects ► • How to CREATE/INSTANTI...
Series Playlist ► • C++
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

Пікірлер: 282
@nazar1744
@nazar1744 7 жыл бұрын
new: hey pls give me 4 bytes Standard-Library: no! get a job !
@exoticcoder5365
@exoticcoder5365 3 жыл бұрын
😂
@erwinschrodinger2320
@erwinschrodinger2320 3 жыл бұрын
Lol
@germinatorz
@germinatorz 7 жыл бұрын
Best C++ series on KZfaq!
@Gilpow
@Gilpow 6 жыл бұрын
Useless comment stating the obvious
@jscorpio1987
@jscorpio1987 4 жыл бұрын
Gilpow he’s just being a nice guy and giving Cherno a compliment. Which is something we need more of in this cold, heartless world.
@garyhahaha5380
@garyhahaha5380 4 жыл бұрын
there isn't any real competition!!!!
@xcaliber6027
@xcaliber6027 4 жыл бұрын
@gilpow check thenewboston, you will be forced to take back your words.
@pierfrancescopeperoni
@pierfrancescopeperoni 3 жыл бұрын
@@jscorpio1987 *brainless world.
@michaelwright8576
@michaelwright8576 3 жыл бұрын
Summary: → Use the new keyword to allocate a specified memory size on the heap in bytes (ex. Int would take 4 bytes of memory) → operating systems must then go and find a contiguous block of memory to match the requested variable type and return a pointer to that memory address. → With a class, it will determine the size of the class and then find a memory allocation → with arrays it will calculate the type of array and multiply by the size of the array. //int * 50 = 200 → The new keyword not only allocates memory, but also calls the constructor → don't forget to use the delete keyword when we use the new keyword. → if we use new keyword with array like new int[], use delete keyword like delete[] → use placement new to i.e new(b) to choose the location of where the memory is stored
@ultimatedragon4281
@ultimatedragon4281 2 жыл бұрын
→The delete keyword also calls the destructor.
@user-kj6lj7dp9j
@user-kj6lj7dp9j 2 ай бұрын
best comment
@saisurisetti6278
@saisurisetti6278 4 жыл бұрын
"Why do you want to learn C++... unless you specifically care about performance, or you specifically care about everything that goes on?" - Cherno the great.
@मेबीराज
@मेबीराज 4 жыл бұрын
- The* Charno* The Great! xD
@awesomedavid2012
@awesomedavid2012 4 жыл бұрын
It's really true if you just want something that works use python or some other language. Coding isn't about "pick your favourite language and stick to it". You pick the language that's best for what you're doing
@darkbolt333
@darkbolt333 4 жыл бұрын
Sai Surisetti I think I don't fit the criteria... I started learning C++ because it has more data structures than Python, it's a common language and Python hates recursive functions. Python has that nasty recursion limit of 1000. And even if I increase that limit (with setrecursionlimit function), it won't go to 50,000.
@damnstupidoldidiot8776
@damnstupidoldidiot8776 4 жыл бұрын
@@darkbolt333 I started learning C++ because it worked with hardware the best, for arduino. But then when I really got started with C++ I loved the syntax and I hate the Python syntax.
@jasperbutcher2596
@jasperbutcher2596 4 жыл бұрын
just here to learn the syntax for fun idk might be going to jail now
@chrisstone-streetlightinte5629
@chrisstone-streetlightinte5629 6 жыл бұрын
I've spent hundreds of hours learning to program and this series, by far, has some of the best explanations of how C++ actually works. Keep it up!
@Djzaamir
@Djzaamir 7 жыл бұрын
Dude , this is my game of thrones now a days , thanks for such an amazing series :)
@vanDalle
@vanDalle Жыл бұрын
Man, you are awsome. I've dropped on one of your films on YT and now I'm in the middle of C++ series, because in 5 min. you are explaining dozens of pages from my book and you're doing it in very easily understandable way. Thanx for your work. All the best from Poland.
@muhammadammar6661
@muhammadammar6661 Жыл бұрын
I cant believe someone can actually explain things like so good. Brilliant job. Much appreciated.
@pacsmile
@pacsmile 7 жыл бұрын
Love your videos, i've been learning quite a lot and using it for embeded c++ programming, keep up the great work!
@papinkelman7695
@papinkelman7695 7 жыл бұрын
"String 28 bytes... just guessing from memory" So, String guess* = new guess(); You guessed from your heap?
@valizeth4073
@valizeth4073 6 жыл бұрын
I love your videos, even though I pretty much know C++, it's always good to watch beginners guide videos, there's always things you've missed.
@Raymoclaus
@Raymoclaus 7 жыл бұрын
Welcome to the C++ series where "we'll talk about it in a future video"
@Banom7a
@Banom7a 7 жыл бұрын
We talk about in soon™
@TheCherno
@TheCherno 7 жыл бұрын
One day it will be complete!
@h.hristov
@h.hristov 7 жыл бұрын
Don't give him a hard time :D, I'm sure he'll go over the advanced topics once he's gone through the basics. As he said, he's trying to make the series as perfect as he wants
@Banom7a
@Banom7a 7 жыл бұрын
no worry, take your time, excellent video as usual
@LucidStew
@LucidStew 7 жыл бұрын
..or he could make one 10 hour video that no one would watch and get it all in one shot.
@MirrorsEdgeGamer01
@MirrorsEdgeGamer01 6 жыл бұрын
_"Please give it to me"_ That's what she said. _0:24__ _"It is actually quite deep."_ That's what she said.
@suyash.01
@suyash.01 3 жыл бұрын
beautiful expatiation. super straightforward and clean and simple.
@alecmather
@alecmather Жыл бұрын
This series is seriously so addicting
@theglitchmindset2256
@theglitchmindset2256 3 жыл бұрын
Cherno is saving me so much time effort MONEY and energy really appreciate you man. i starting this series September 2020 almost halfway there
@WeberJ81
@WeberJ81 5 жыл бұрын
@TheChernoProject I admire the videos, really simplifies C++ and i'm still learning new things about it from these, also big fan of the ibanez in the background, just don't lean it on the stock, it warps the neck, guitar teacher playing 26 years/Senior Software Engineer to C++ teacher tips :), thanks for the videos
@tef6477
@tef6477 7 жыл бұрын
Thank you so much . Was so used to malloc(sizeof)). Keep it up mate .
@samruddhipaiyawal5586
@samruddhipaiyawal5586 5 ай бұрын
wow that was actually very informative!! thankyou!
@leixun
@leixun 4 жыл бұрын
*My takeaways:* 1. The main purpose of *new* is to allocate memory for the user's need on the heap 1:25 2. MUST use *delete* with new 7:45
@kenamreemas3295
@kenamreemas3295 5 жыл бұрын
As soon as I completed watching this vid, I tried to use delete and see if calls the destructor.. and it DOES!!
@dx2002sg
@dx2002sg 3 жыл бұрын
wow definitely deeper than i thought for this "new"
@h.hristov
@h.hristov 7 жыл бұрын
Thanks yet again for the awesome video!
@BlackJar72
@BlackJar72 6 жыл бұрын
Well, I'm watching these videos because you often throw interesting and potentially useful detail most books don't mention (and my one actual class didn't either).
@umairalvi7382
@umairalvi7382 4 жыл бұрын
Heyy cherno a big fan of yours im watching your c++ series for quite a long time and in one video you said that you're gonna come with a project in c++ very soon.when are you going to come with that project its been a long long time please upload it as soon as possible it will be extremely helpful. Thank youu
@ibiixie
@ibiixie 6 жыл бұрын
The standard library looks so complicated lol
@mmaranta785
@mmaranta785 3 жыл бұрын
Thanks for your help. Your videos are very helpful.
@Basel-ll8fj
@Basel-ll8fj 2 жыл бұрын
Best C++ series ❤❤
@adityagoyal6964
@adityagoyal6964 3 жыл бұрын
You are insane cherno. After 1 month i only open my instagram account just to follow you. Keep up the good work and you will surely get that love what you deserve❤❤❤❤❤
@AgentM124
@AgentM124 7 жыл бұрын
The New Keyword! DELETE IT
@motbus3
@motbus3 4 жыл бұрын
i know somewhat of cpp but i was watching the full series for a review... and i today i learned that new can have a specific allocation address... thats so cool
@haykav
@haykav 6 жыл бұрын
When you opened up the definition for new and I saw that it's just an operator for giving a pointer the required amount that it would neeeeeeed to stoooreee on the heap, I was like OH MY GAWDDD, My mind has been blown!!
@Destroyer19941995
@Destroyer19941995 3 жыл бұрын
Thank you for teaching me this.
@soulimanemammar2909
@soulimanemammar2909 2 жыл бұрын
There is something else to mention: when we call the new operator, it's actually a syscall (in terms of operating systems) and when a syscall happens our program loses control (the os regains the control to fulfill the request -in our case memory allocation-) and it's up to the os scheduler to decide which process will be given the control once the syscall handling finished (and most of the time it's not our program that will regain control)
@Usammityduzntafraidofanythin
@Usammityduzntafraidofanythin 2 жыл бұрын
Well unless the program is selected by the user at the time. I read that every process in the computer is being maintained by the cpu just flopping through them very very quickly over and over; programs unselected by the user are just put on pause if they have that feature in them, I guess.
@tmvkrpxl0135
@tmvkrpxl0135 3 жыл бұрын
I get a weird feeling from your videos, I thought I know well enough about some topic but there's always something more when I watch your videos
@thomiadityaalhakiim5831
@thomiadityaalhakiim5831 2 жыл бұрын
ok let me save this playlist on the heap
@oni_thefirst
@oni_thefirst 5 жыл бұрын
I like how he used new for like 6 videos in a row before noticing that he never explained what it is. Great tutorials either way
@RobertMilat
@RobertMilat 2 жыл бұрын
The most memorable part of this video is that malloc sounds very evil to me
@jeeperscreeperson8480
@jeeperscreeperson8480 3 жыл бұрын
Heap allocation is slow mainly because the kernel has a lot of stuff to do besides fulfilling your memory requests. I believe the kernel also sleeps for a fixed period of time every so often. Also, because the kernel can supply you with a chunk of memory of any size, the heap is fragmented. Idk how the windows kernel handles defragmentation, but I assume it defragments memory every time you ask for a big chuck. All the more reasons to ask as few times as possible.
@NexGenSlayer
@NexGenSlayer 6 жыл бұрын
Please do a video on linked lists and nodes! These are really important and pretty confusing
4 жыл бұрын
Those are actually about data structures, it's not something about the C++ itself.
@sebastiangudino9377
@sebastiangudino9377 2 жыл бұрын
I wouldn't say they are "really important". Yes, they are a phenomenal way to implement sequential data when you know you will be performing many insertions and concatenation. As well as when you want to implement something like a tree. But in day to day you are either going to use them because they are your language's preferred way to handle lists, like Haskell or Scala. Or you are not really going to use them very much. They actually tend to get overused by beginners. Since when all you have is a hammer everything looks like a nail. Most of the time a Dynamic Array (So a Vector in C++) is what we really want. You wouldn't default to storing you data in a linked list unless you have a particular optimization or algorithm in mind you would want to use
@AlbertoRivas13
@AlbertoRivas13 4 жыл бұрын
very useful sir thank a lot
@krisitak
@krisitak 4 жыл бұрын
There is a difference between the "new expression" and "operator new". Operator new is pretty much equivalent to malloc except it can be overloaded/specialized. The "new expression" picks an appropriate operator new to call which returns a block of memory and then the constructor is called on the memory returned by the operator.
@raht9578
@raht9578 3 жыл бұрын
THANK YOUUU
@ohwow2074
@ohwow2074 3 жыл бұрын
Jesus!! This video was soooo informative!!!
@strangeruler2317
@strangeruler2317 2 жыл бұрын
For people wondering what the variables contain could be if malloc function wont call constructer: Constructer intializes the data so, malloc allocated data supposed to untialized and should show random values i.e Int *a = malloc(sizeof(int)); cout
@batteryjuicy4231
@batteryjuicy4231 3 ай бұрын
this was very helpfull keep up the good job. I love this series! It has helped me A LOT!
@WJSWebster
@WJSWebster 7 жыл бұрын
FOR THE LOVE OF GOD PLEASE BLINK!
@VoidAshen
@VoidAshen 3 жыл бұрын
being anxious with his hand near the cactus
@stercolaireotwo9285
@stercolaireotwo9285 6 жыл бұрын
Thanks for your tutorial. Are you planing to teach some optimizations in object instantiation frecuently used in game engines (such as object pools and instead of allocating and instantiating N objects separately, allocate the memory those N objects require at once and then instantiate all the objects in that chunk of memory)?
@joseph555able
@joseph555able 4 жыл бұрын
Finally!! Thank you
@nukeulater
@nukeulater 7 жыл бұрын
nigga these tuts are god's work! good job (i just found you :D), i understood more c++ than i do at school, keep it up
@LucidStew
@LucidStew 7 жыл бұрын
hair is too neat.
@anassqadil1376
@anassqadil1376 2 жыл бұрын
Bro U are a legend Thanks
@ShonePizza
@ShonePizza 6 жыл бұрын
Guys, you can't use "delete" with "malloc()"
@JuvStudios
@JuvStudios 4 жыл бұрын
but you can use free()
@kenan2386
@kenan2386 2 жыл бұрын
It basically allocates something properly
@phantomstriker7996
@phantomstriker7996 Жыл бұрын
New is when you want to allocate a specific amount of memory in the heap
@arturopopoli2395
@arturopopoli2395 5 жыл бұрын
thanks a lot!
@samdavepollard
@samdavepollard 3 жыл бұрын
If you're new, use new. None of that malloc malarkey. Difficult to believe we're not even halfway through this series yet! Many Thanks for sharing your knowledge.
@codastudiode
@codastudiode 2 жыл бұрын
You saved my life!
@smileynetsmileynet7922
@smileynetsmileynet7922 3 жыл бұрын
You would write in C++, because you need native code, that works on Linux AND Windows. Until my languages can write themselves in themselves, there ISN'T really a better way. As of this writing, the development version has ALMOST the same features as C, which would be the first BIG milestone.
@Hoppitot
@Hoppitot 2 жыл бұрын
Thx for the malloc chief, don't worry I got this
@user-wl3nd6si9l
@user-wl3nd6si9l 7 жыл бұрын
Does delete call destructor?
@TheCherno
@TheCherno 7 жыл бұрын
+Роман Капуста yes
@Usammityduzntafraidofanythin
@Usammityduzntafraidofanythin 2 жыл бұрын
It is incredible how powerful c++ is. I'd learn just out of respect.
@halemm
@halemm 7 жыл бұрын
hey cherno, where did you learn all this stuff, at work or at university? thanks!
@philmarsh7723
@philmarsh7723 4 жыл бұрын
1. Because I know C++ better than Java. 2. Because C++ supports operator overloading (complex data type) and I do scientific programming. 3. Because C++ has sufficient math, GUI, and analysis libraries, Golang doesn't (yet).
@iyaehsan3840
@iyaehsan3840 3 жыл бұрын
Ik this is completely unrelated but your eye color is so pretty XD
@sachinpandhare8737
@sachinpandhare8737 6 жыл бұрын
I would like to correct something , please !!!!!! malloc(): int *a = new int; --- > will internally call the malloc() and allocate the 4 bytes on the heap and return the pointer to int, calloc(): int *a= new int[50]; ---> calls a calloc() and allocates 50 contiguous blocks of 4 byte each and returns a pointer to the first block , but it should be called a pointer to the array of integers. memory will always be allocated on heap with calloc or malloc as its dynamically allocated , one more interesting part is if you do char *strp = "TheChemo is great" ; this will also put this string on heap but a separate part of a heap called literal pool i guess (learned this 4 years before don't really remember) and this is kind of const and you can;t update this as its ---(a C programmer )
@kenan2386
@kenan2386 2 жыл бұрын
C++ is cool and all but have you tried blinking?
@MultiPwolf
@MultiPwolf 7 жыл бұрын
c++ doesn't guarantee that an int is 4 bytes, only that it is at least 4 bytes. It isn't guaranteed by the specification and although most compilers use 4 byte ints you aren't assured of it. It would be more accurate to say that you get 50 * sizeof(int) bytes. --- Edit: As mentioned by Peterolen an int is only guaranteed to be at least 2 bytes.
@fusselrulezz
@fusselrulezz 7 жыл бұрын
He just said "A Integer is 4 bytes" for us to imagine how that stuff works. Not to specifically declare "YES! A INTEGER IS 4 BYTES EVERYTIME"
@MultiPwolf
@MultiPwolf 7 жыл бұрын
I can't speak for his mind, only what some proportion of viewers will take from that. His videos are excellent but it's better for someone to point out the small stuff that could lead to hours of confusion for lots of people down the line.
@MultiPwolf
@MultiPwolf 7 жыл бұрын
Good point! My mistake.
@LaT3St
@LaT3St 6 жыл бұрын
For people who are coming from a managed language, C++ by itself is pretty confusing and complicated. We need to learn such things at some point, but I think a beginner-series is the wrong place for such a conversation. If I happen to debug a program and I notice some unexpected behaviour from the program, I will search for the reason and learn more details. This will lead me to being a more skilled programmer over time. But for now, simplification has to be done, otherwise I (and many others) will give up and be frustrated.
@MultiPwolf
@MultiPwolf 6 жыл бұрын
I disagree, debugging is a great way to learn but that doesn't mean you should purposefully make life harder over trivial matters. It's a tiny thing to bear in mind, datatypes are given a minimum range by the standard and not an exact size. You remember something like that early and on then you spend your hours debugging more interesting things, than finding out that you've expected the size to be 4 bytes because all the books and videos you learnt from said it was 4 bytes. A beginner series should cover the fundamentals in some depth so that you have a foundation upon which to build your knowledge base. A beginner series is not the place for poor examples and obscurity, even if you appreciate the value of learning from debugging. A matter of opinion but there are all too many tutorials favouring your side of the fence and not enough favouring ours. This was one of very few oversights in this series thus far(in time, not just up to this video) and to point out the small issues that could be misleading or unhelpful does not diminish his content. If anything, a good comment section with good discussion is just as important as having good content. It's easier to trust content when it is followed by good discussion and it is easier to trust your knowledge when any bad habits or misguided ideas when are being pointed out by the audience.
@awildtomappeared5925
@awildtomappeared5925 7 жыл бұрын
If this is the new keyword, what is the old keyword?
@arbaazmohammed2041
@arbaazmohammed2041 5 жыл бұрын
lmao
@HermanWillems
@HermanWillems 5 жыл бұрын
delete(); After it... it's old. You can do like: #define delete old (not serious advice)
@vertigo6982
@vertigo6982 5 жыл бұрын
it got deprecated. ;)
@lionkor98
@lionkor98 5 жыл бұрын
hello dad
@ayushjindal4981
@ayushjindal4981 5 жыл бұрын
"this" is not the new keyword. "new" is the new keyword. "this" is used to refer to the object currently being considered. Hope that helped!
@industrialdonut7681
@industrialdonut7681 3 жыл бұрын
just had a blast allocating as much memory as I could in 0 ints !!! Got up to 11GB before windows paged the rest
@shahidk2223
@shahidk2223 7 жыл бұрын
please make a video about cstrings and lpcstr
@pixarfilmz4769
@pixarfilmz4769 6 жыл бұрын
love
@patrickg2416
@patrickg2416 4 жыл бұрын
that Ibanez shred machine >>> I see you
@timothy8941
@timothy8941 Жыл бұрын
I was following some tutorials for building a game engine that called for the use of the new operator for some reason it always gave me an undefined reference to constructor error. So I tried using malloc as you described and it worked. Not sure what this means could just be my compiler but im going to continue to use malloc untill it gets me in trouble same for delete. Thank you for the video
@marianionita3282
@marianionita3282 2 ай бұрын
malloc doesn't call the constructor
@sumitkamble_
@sumitkamble_ Жыл бұрын
No more confusion with new
@ScienceMarcYT
@ScienceMarcYT 6 жыл бұрын
I'm assuming the memory gets freed when the program ends if you don't call delete?
@paherbst524
@paherbst524 2 жыл бұрын
question: is there a way to profile where in an application is calling new?
@hubtubsub5209
@hubtubsub5209 2 жыл бұрын
Just like new calls malloc internally, when we call delete does it internally calls *free* too?
@HAZARD_LIGHTS
@HAZARD_LIGHTS 2 жыл бұрын
I just leaned how to create a memory leak yay!
@user-mh6hw3ed6q
@user-mh6hw3ed6q 3 жыл бұрын
int*b= new int[50] i can use Entity* e= new(the place i wanna save) , but not used probably
@brentstockton5742
@brentstockton5742 4 жыл бұрын
if could "using namespace std;" that would be greaaat
@fastlife9482
@fastlife9482 3 жыл бұрын
Phata Baas. Blood coming out of ears
@youcaillou
@youcaillou 5 жыл бұрын
I have been watching all the C++ videos, from the first to this one. First things first: These videos are amazing. Coming from JavaScript, I find it super easy to learn about the concepts of C++. There is just one thing I would like to point out: You often use the word `class` when you actually mean `object`. This can be super confusing, e.g. at 1:25 in this video you say: "Easy, I'll just create a new class". This is completely different to saying "Create a new object". I am sure you are aware of this, I just want to point out that it often confuses me, when watching the videos. And with that, I shall continue watching. PS: Is there another way to donate money to you than through Patreon? I would love to make a bigger one time donation, rather than a subscription.
@Usammityduzntafraidofanythin
@Usammityduzntafraidofanythin 2 жыл бұрын
Any time creates a brand new func or class, he calls them definitions. There's a difference between Def and init/declaration
@rahulor2478
@rahulor2478 Жыл бұрын
what will happen if the program crashes before we call 'delete'
@1Naif
@1Naif 7 жыл бұрын
you are awesome.
@ixwix
@ixwix 3 жыл бұрын
so, if I don't call delete, the memory will stay blocked until I restart my computer?
@Crossbow123
@Crossbow123 7 жыл бұрын
When allocating an array like new Entity[n], does the constructor get invoked as well for each object?
@Crossbow123
@Crossbow123 7 жыл бұрын
Thanks. Good point =)
@zacharynicoll4312
@zacharynicoll4312 5 жыл бұрын
Take a shot every time he says 'future video' or 'another video'.
@b78418364
@b78418364 5 жыл бұрын
So basically normal objects and variables use stack memory (which means the memory it needs can change based on the value they hold), but by declaring them with the new keyword basically we limit their memory to 4 bytes or so ? ...
@omerkaragoz
@omerkaragoz 7 жыл бұрын
Why there is a second const after GetName() on line 14?
@mr.budders8740
@mr.budders8740 3 жыл бұрын
0:46 "Especially now in 2017"
@mlntdrv
@mlntdrv Жыл бұрын
So, in short the new keyword is all about explicit memory management. No relation to object creation at all - the ctor handles this. Basically the guy wanted to borrow some stuff from other languages (Simula perhaps) but ended up making something entirely different. Sounds to me like new could have been called 'heap' instead. Honestly, (m/c)alloc at least were honest about what they do.
@joseluismatabuenasedano6881
@joseluismatabuenasedano6881 Жыл бұрын
what happens if you don't delete?
@alexdumea
@alexdumea 7 жыл бұрын
Hey Cherno, do you plan on making a video about CMake sometime?
@TheCherno
@TheCherno 7 жыл бұрын
Yes, when we start talking about cross-platform development.
@alexdumea
@alexdumea 7 жыл бұрын
TheChernoProject Awesome! Love your videos, keep it up!
@Skaarjy
@Skaarjy 4 жыл бұрын
Weird question, it's been decades, literally, since I used C. (Not C++, but good ole C). Wasn't there different ways to allocate storage besides new and malloc/calloc/realloc? I remember compact/small/tiny/..../large/huge memory models, but I vaguely remember something about allocating memory.
@xrafter
@xrafter 4 жыл бұрын
Yes, there is
@bogulans2897
@bogulans2897 3 жыл бұрын
God bless youtube recommendation, and god bless you!
@serkanozturk4217
@serkanozturk4217 Жыл бұрын
Personal Notes: - Heap memory is allocated contiguously
@footballCartoon91
@footballCartoon91 2 жыл бұрын
@6:57 "what new does is return a void* pointer" my next question is does void* pointer that points to object exist on the stack? for example: /* Entity* e=new Entity(); Entity* allEntity=new Entity[35,714]; //full stack size 1e6/28 bytes#in python //meaning: a pointer to an array of objects// that pointer exist //on stack whereas the array on the heap Entity** allEntityOnTheHeap= new Entity*[35,714]; // cannot tell the difference */ does e exist on the stack? does allEntity exist on the stack? what is the difference between allEntity and allEntityOnTheHeap?
@williamchamberlain2263
@williamchamberlain2263 5 жыл бұрын
Is there significant overhead in allocating memory for the stack on each new scope? I suspect that that is down to how smart the OS is in its interface and interactions with the Standard Library, but that's me being naive.
@theshermantanker7043
@theshermantanker7043 2 жыл бұрын
Thread stacks are usually native, it's usually heap allocations that need the OS's help
Implicit Conversion and the Explicit Keyword in C++
7:54
The Cherno
Рет қаралды 183 М.
How to CREATE/INSTANTIATE OBJECTS in C++
13:03
The Cherno
Рет қаралды 239 М.
Пранк пошел не по плану…🥲
00:59
Саша Квашеная
Рет қаралды 6 МЛН
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 36 МЛН
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 293 М.
C++ 24. Перегрузка new и delete. Аллокаторы
1:43:14
Лекторий ФПМИ
Рет қаралды 8 М.
How C++ took a turn for the worse
5:03
Code Persist
Рет қаралды 268 М.
lvalues and rvalues in C++
14:13
The Cherno
Рет қаралды 308 М.
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 240 М.
Stack vs Heap Memory in C++
19:31
The Cherno
Рет қаралды 560 М.
CONST in C++
12:54
The Cherno
Рет қаралды 398 М.
unique_ptr: C++'s simplest smart pointer
11:54
mCoding
Рет қаралды 41 М.
SINGLETONS in C++
19:16
The Cherno
Рет қаралды 197 М.