You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: assign7/short_answer.txt
+15-7Lines changed: 15 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,21 @@ Unique Pointer
5
5
--------------
6
6
7
7
Q1. List one or two benefits of using RAII to manage memory instead manually calling `new` and `delete`.
8
-
A1. TODO
8
+
A1. No need to necessary manager memory to avoid forgetting to delete and
9
+
causing memory leak.
9
10
10
-
Q2. When implementing move semantics for a `unique_ptr`, for example in the move constructor `unique_ptr(unique_ptr&& other)`, it is essential that we set the underlying pointer of the `other` parameter to `nullptr` before exiting the function. Explain in your own words what problem would arise if we did not.
11
-
A2. TODO
11
+
Q2. When implementing move semantics for a `unique_ptr`, for example in the
12
+
move constructor `unique_ptr(unique_ptr&& other)`, it is essential that we
13
+
set the underlying pointer of the `other` parameter to `nullptr` before
14
+
exiting the function. Explain in your own words what problem would arise
15
+
if we did not.
16
+
A2. two pointer -> same one address.
12
17
13
-
Q3. This method of recursive deallocation through RAII works great for small lists, but may pose a problem for longer lists. Why? Hint: what is the limit for how "deep" a recursive function's call stack can grow?
14
-
A3. TODO
18
+
Q3. This method of recursive deallocation through RAII works great for
19
+
small lists, but may pose a problem for longer lists. Why? Hint:
20
+
what is the limit for how "deep" a recursive function's call stack can grow?
21
+
A3. windows~1MB linux~8MB macos~8MB
15
22
16
-
Q4. What does `std::move` do in this context? Why is it safe to use `std::move` and move semantics here?
17
-
A4. TODO
23
+
Q4. What does `std::move` do in this context? Why is it safe to
24
+
use `std::move` and move semantics here?
25
+
A4. use std::move -> Object not to use copy, Instead 'move'.
0 commit comments