Dec. 12, 2015
Enjoy 2 hours to read the book: tour of C++ on Saturday morning.
A Tour of C++
http://www.amazon.com/A-Tour-C-In-Depth/dp/0321958314
Plan to spend 10 hours to read the book.
First 3 hours reading, here are favorite advice from the book:
the chapter 9 - containers Page (104-105)
Advice:
1. Use vector as your default container
8. User push_back() or resize() on a container rather than realloc on an array
13. To preserve polymorphic behavior of elements, store pointers (Julia's rating: A)
14. Insertion operators, such as insert() and push_back() are often surprisingly efficient on a vector.
17. A map is usually implemented as a red-black tree.
18. An unordered_map is a hash table.
19. Pass a container by reference and return a container by value (Julia: look into this advice more)
20. For a container, use the ()-initializer syntax for sizes and the {}-initializer syntas for elements.
21. Prefer compact and contiguous data structure (Julia's rating: A)
22. A list is relatively expensive to traverse.
23. Use unordered containers if you need fast lookup for large amounts of data.
24. User ordered associative containers (e.g., map and set) if you need to iterate over their elements in order
25. Use unorderd containers for element types with no natural order.
28. Know your standard-library containers and prefer them to hand-crafted data structures.
When Julia works on leetcode algorithms question early in 2015, she found out that most talent programmers tend to use C++ to write solution. Now, she is determined to finish this book reading: a tour of C++, she likes to master C++ some day.
Further reading on the advice 13 (Dec. 12, 2015):
http://stackoverflow.com/questions/141337/c-stl-should-i-store-entire-objects-or-pointers-to-objects
http://stackoverflow.com/questions/22146094/why-should-i-use-a-pointer-rather-than-the-object-itself?rq=1 (Julia enjoys reading the blog, she spends over 30 minutes on this blog.)
Notes from the above stackoverflow blogs:
Dynamic allocation
You need the object to outlive the current scope
You need to allocate a lot of memory
Pointers
You need reference semantics
You need polymorphism
You want to represent that an object is optional
You want to decouple compilation units to improve compilation time
You need to interface with a C library
Polymorphic behavior
Reference semantics and avoiding copying
Resource acquisition
More fine-grained life-time control
http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap
From January 2015, she started to practice leetcode questions; she trains herself to stay focus, develops "muscle" memory when she practices those questions one by one. 2015年初, Julia开始参与做Leetcode, 开通自己第一个博客. 刷Leet code的题目, 她看了很多的代码, 每个人那学一点, 也开通Github, 发表自己的代码, 尝试写自己的一些体会. She learns from her favorite sports – tennis, 10,000 serves practice builds up good memory for a great serve. Just keep going. Hard work beats talent when talent fails to work hard.
Showing posts with label containers. Show all posts
Showing posts with label containers. Show all posts
Saturday, December 12, 2015
Subscribe to:
Posts (Atom)