Generic pointers, native pointers and smart pointers, and pointer intelligence

Source: Internet
Author: User

Generic pointers, native pointers and smart pointers, and pointer intelligence

1. Generic pointer
Generic pointers have many meanings.
(1) refers to the void * pointer, which can point to any data type, so it has the meaning of "generic.
(2) refers to a generic data structure with pointers, including generic iterators and smart pointers.
Broadly speaking, an iterator is an opaque pointer that can traverse access operations. Generally, an iterator refers to a narrow iterator, that is, an instance of classes implemented based on generic iterator_traits in C ++-based STL.
In general, generic pointers and iterators are two different concepts, and the intersection of them is the iterator class.
2. The native pointer is a normal pointer. Compared with it, it acts like a pointer, but it is not a pointer.
"Native" refers to "the simplest and most basic one ". Because many things are abstracted and theoretically made, "the simplest and most basic pointer of the past" is just one of the manifestations of abstract concepts (such as iterator.
3. smart pointer is a concept in C ++: Since C ++ does not have an automatic memory reclaim mechanism, programmers have to handle memory-related problems each time, however, using smart pointers can effectively alleviate such problems.
The introduction of smart pointers can prevent suspension of pointers.
Generally, a pointer is encapsulated into a smart pointer class. In addition, a counter is encapsulated in this class. operations such as copying a pointer will increase the value of this counter by 1, the delete operation on the pointer is reduced by 1. When the value is 0, the pointer is NULL.

How can we distinguish between generic pointers, native pointers and smart pointers?

1. Generic pointer
Generic pointers have many meanings.
(1) refers to the void * pointer, which can point to any data type, so it has the meaning of "generic.
(2) refers to a generic data structure with pointers, including generic iterators and smart pointers.
Broadly speaking, an iterator is an opaque pointer that can traverse access operations. Generally, an iterator refers to a narrow iterator, that is, an instance of classes implemented based on generic iterator_traits in C ++-based STL.
In general, generic pointers and iterators are two different concepts, and the intersection of them is the iterator class.
2. The native pointer is a normal pointer. Compared with it, it acts like a pointer, but it is not a pointer.
"Native" refers to "the simplest and most basic one ". Because many things are abstracted and theoretically made, "the simplest and most basic pointer of the past" is just one of the manifestations of abstract concepts (such as iterator.
3. smart pointer is a concept in C ++: Since C ++ does not have an automatic memory reclaim mechanism, programmers have to handle memory-related problems each time, however, using smart pointers can effectively alleviate such problems.
The introduction of smart pointers can prevent suspension of pointers.
Generally, a pointer is encapsulated into a smart pointer class. In addition, a counter is encapsulated in this class. operations such as copying a pointer will increase the value of this counter by 1, the delete operation on the pointer is reduced by 1. When the value is 0, the pointer is NULL.

In C language, since generic pointers exist, why do we need to differentiate common pointers in data classes?

Void * pointer cannot be unreferenced...
The normal pointer type carries one of the methods used to access that object ..
If there is no type, the object cannot be accessed ..

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.