Page 49 of 68

Re: Noob learns to code in 3 months

Posted: July 18th, 2017, 3:27 pm
by chili
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.

Re: Noob learns to code in 3 months

Posted: July 18th, 2017, 3:49 pm
by Yumtard
^ Oh yeah, linked list took a lot of trial and error even after reading a bunch :D

Re: Noob learns to code in 3 months

Posted: July 20th, 2017, 4:09 am
by chili
One piece of advice: don't do this:

Code: Select all

this->~Stack();
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.

Re: Noob learns to code in 3 months

Posted: July 20th, 2017, 6:45 am
by albinopapa
Hey Chili, Is there ever a case for NEEDING to call the dtor directly?

Re: Noob learns to code in 3 months

Posted: July 20th, 2017, 2:54 pm
by cameron
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....)

Re: Noob learns to code in 3 months

Posted: July 20th, 2017, 6:05 pm
by albinopapa
@cameron: I'm assuming you'd want to write those for a custom allocator, correct?

Re: Noob learns to code in 3 months

Posted: July 21st, 2017, 8:49 am
by chili
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.

Re: Noob learns to code in 3 months

Posted: July 21st, 2017, 2:58 pm
by Yumtard
^ 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.

Re: Noob learns to code in 3 months

Posted: July 23rd, 2017, 9:05 pm
by Byteraver
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

Posted: July 24th, 2017, 9:32 am
by Yumtard
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.
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.

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