gpt4 book ai didi

c++ - "owning"在编程上下文中是什么意思?

转载 作者:行者123 更新时间:2023-12-04 12:13:55 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





What is ownership of resources or pointers?

(1 个回答)


2个月前关闭。




cppreference用它来描述
std::string_view:


devtut

sodocumentation
也用它来描述 std::string_view :

C++17 introduces std::string_view, which is simply a non-owning range ofconst chars, implementable as either a pair of pointers or a pointer and alength.


various other questions and answers在这里 SO
引用它,但我找不到它的含义的任何解释。

最佳答案

您可以拥有资源,即任何数量有限的东西。这通常是内存或系统句柄。拥有资源的任何人都负责在使用完资源后将其释放。std::unique_ptrstd::shared_ptr是拥有包装器的示例。当它不再使用时,它会释放它们的内存。任何其他 RAII 也是如此类(class)。std::basic_string_view是非拥有的,这是一个很好的说法,它不以任何方式绑定(bind)到字符串的实际生命周期,并且如果您不小心,如果字符串重新分配,它可能会悬挂。

关于c++ - "owning"在编程上下文中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68689873/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com