Noob learns to code in 3 months
Re: Noob learns to code in 3 months
Well, better to feel confused than to have a false sense of mastery, that's my philosophy. You must have absorbed a fair bit of the lesson if you managed to get the container to work without leaking any memory. Good job on figuring out linked lists on your own as well. That part is at least as difficult as the deep copy/rule of 3 stuff.
Chili
Re: Noob learns to code in 3 months
^ Oh yeah, linked list took a lot of trial and error even after reading a bunch
Re: Noob learns to code in 3 months
One piece of advice: don't do this:
I see where the temptation comes in, but if you really want to do code reuse (a good impulse/desire), do like papa did and make a separate private member function for freeing resources and call it from your dtor/copy assign/etc.
Code: Select all
this->~Stack();
Chili
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Noob learns to code in 3 months
Hey Chili, Is there ever a case for NEEDING to call the dtor directly?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Noob learns to code in 3 months
Well, I am not chilli but... if you ever want to fool around with writing construct/destruct functions similar to new/delete you gotta. (or perhaps overloading....)
Computer too slow? Consider running a VM on your toaster.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Noob learns to code in 3 months
@cameron: I'm assuming you'd want to write those for a custom allocator, correct?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Noob learns to code in 3 months
Yup I was gonna say something similar.
Actually, when you use shared_ptr with make_shared, the control block and the payload object are allocated with a single heap allocation, so I believe the internal implementation calls dtor when the use count reaches 0 (so the object can free its resources), and then frees the combined payload/control block heap memory when both the use count and the weak count are 0.
And like cam says, any kind of custom allocation is gonna require your calling the dtor directly, as well as in-place construction I guess.
Actually, when you use shared_ptr with make_shared, the control block and the payload object are allocated with a single heap allocation, so I believe the internal implementation calls dtor when the use count reaches 0 (so the object can free its resources), and then frees the combined payload/control block heap memory when both the use count and the weak count are 0.
And like cam says, any kind of custom allocation is gonna require your calling the dtor directly, as well as in-place construction I guess.
Chili
Re: Noob learns to code in 3 months
^ I'm barely following you guys:P
I got held up a couple of days due to sleeping issues leaving me tired all day + trying to write a wedding speech for my brother. But now I've watched the video about matrices and rewatched the video about rotation and am going to open up the math book today.
I got held up a couple of days due to sleeping issues leaving me tired all day + trying to write a wedding speech for my brother. But now I've watched the video about matrices and rewatched the video about rotation and am going to open up the math book today.
Re: Noob learns to code in 3 months
I'm a bit late to the discussion but I found Khan's Academy (https://www.khanacademy.org/) extremely useful to review trigonometry, functions and matrices (math in general). He explains it very well and the exercises help to anchor the knowledge firmly. It took me a few months worth of evening study to review it all but definitely helped whilst programming my breakout / arkanoid clone somewhat later.
Re: Noob learns to code in 3 months
Awesome! Will check it out once I'm done with the book to go into more details. The book I'm reading is more of an overview of the subject.Byteraver wrote:I'm a bit late to the discussion but I found Khan's Academy (https://www.khanacademy.org/) extremely useful to review trigonometry, functions and matrices (math in general). He explains it very well and the exercises help to anchor the knowledge firmly. It took me a few months worth of evening study to review it all but definitely helped whilst programming my breakout / arkanoid clone somewhat later.
Finished the fundamentals part which briefly explained
- complex numbers
- implications and equicalence
- set theory
- functions, onto, one-to-on and inverse
- linear transformations
next 2 chapters are matrices and the 2 after that are vectors followed by Linear transformations and eigenvalues and eigenvectors.
Will try to look into all these subjects on khan afterwards