13 Matching Annotations
  1. Apr 2022
    1. If a compiler cannotdetermine whether or not two pointers may be aliased, it must assume that eithercase is possible, limiting the set of possible optimizations.

      pointer alias 的 optimization block 怎么理解?

    2. The case where two pointers may designate the same memory location isknown as memory aliasing.

      什么是 memory alias?

    1. std::shared_ptr can be used when you need multiple smart pointers that can co-own a resource. The resource will be deallocated when the last std::shared_ptr goes out of scope. std::weak_ptr can be used when you want a smart pointer that can see and use a shared resource, but does not participate in the ownership of that resource.

      weak_ptr 的适用场景

    1. Always make a copy of an existing std::shared_ptr if you need more than one std::shared_ptr pointing to the same resource.

      如果要创建多个 shared_ptr,推荐的做法是什么?

    1. Second, don’t manually delete the resource out from underneath the std::unique_ptr.

      有什么误用 std::unique_ptr 的情况?

    2. Use std::make_unique() instead of creating std::unique_ptr and using new yourself.

      推荐的创建 std::unique_ptr 的方式是什么?有什么好处?

    3. Favor std::array, std::vector, or std::string over a smart pointer managing a fixed array, dynamic array, or C-style string.

      对于固定的 array,动态 array 和字符串,更推荐使用哪种类型?

    4. Because std::unique_ptr is designed with move semantics in mind, copy initialization and copy assignment are disabled. If you want to transfer the contents managed by std::unique_ptr, you must use move semantics.

      std::unique_ptr 可以使用 copy 初始化吗?

  2. Mar 2022
    1. A Smart pointer is a composition class that is designed to manage dynamically allocated memory and ensure that memory gets deleted when the smart pointer object goes out of scope.

      smart pointer 是什么?有什么好处?

  3. Feb 2022
    1. The final example shows that one cancompute the difference of two pointers within the same data structure, with theresult being data having type long and value equal to the difference of the twoaddresses divided by the size of the data type.

      如何计算两个 pointers 的差?

    2. if p is a pointer to dataof type T , and the value of p is xp, then the expression p+i has value xp + L . i,where L is the size of data type T


  4. Nov 2021
    1. we see that whatwe call “pointers” in C are simply addresses. Dereferencing a pointer involvescopying that pointer into a register, and then using this register in a memoryreference.

      dereference pointer 在 assembly code 中如何实现?

    1. One of the best things about classes is that they contain destructors that automatically get executed when an object of the class goes out of scope. So if you allocate (or acquire) memory in your constructor, you can deallocate it in your destructor, and be guaranteed that the memory will be deallocated when the class object is destroyed (regardless of whether it goes out of scope, gets explicitly deleted, etc…).

      smart pointer 的原理是什么?