Back To Basics Lifetime Management
0 码力 | 66 页 | 8.43 MB | 5 月前3Object Lifetime: From Start to Finish
Object Lifetime From Start to Finish Thamara Andrade | https://thamara.dev/34 Me finally understanding why my code was failing… ... and realizing I didn’t really understand the rules for object object lifetime.What is object lifetime anyway? 567You can expect… but not… •Review of object lifetime •(A Little of) RAII •Beyond basic lifetime •Common pitfalls •Value categories •Unions/Arrays •Any ObjWithVirtualFunction o2; Non-vacuous initialization Vacuous initialization 1617 When lifetime starts?18 When lifetime starts?20 Constructors & Destructorshttps://godbolt.org/z/ffzG8hPT8 struct Foo {0 码力 | 214 页 | 9.34 MB | 5 月前3Lifetime Safety in C++: Past, Present and Future
Horvath@microsoft.comTake our survey Win prizes https://aka.ms/cppcon/lifetime Welcome to CppCon 2023! Come by our booth and join #visual_studio channel on CppCon Discord https://aka 2021 Now 2022 Gabor.Horvath@microsoft.comApproaches to safety C++ is getting safer The lifetime safety toolbox What comes next?Memory Safety • Microsoft: 70 percent of all security bugs • -fbounds-safety, buffer hardening Temporal safety • ASAN, GWP-ASAN, HWASAN + Fuzzing • Lifetime Safety Profile, Crubit • C26815, C26816 • Cyclone, P2771 • -Wdangling-gsl • -Wdangling-reference0 码力 | 124 页 | 2.03 MB | 5 月前3The Rust Programming Language,2nd Edition
at the closing }. Note: In C++, this pattern of deallocating resources at the end of an item’s lifetime is sometimes called Resource Acquisition Is Initialization (RAII). The drop function in Rust will dangle() -> &String { let s = String::from("hello"); &s } Here’s the error: error[E0106]: missing lifetime specifier --> dangle.rs:5:16 | 5 | fn dangle() -> &String { | ^^^^^^^ | = help: this function's borrowed value, but there is no value for it to be borrowed from = help: consider giving it a 'static lifetime error: aborting due to previous error This error message refers to a feature we haven’t covered0 码力 | 617 页 | 1.54 MB | 1 年前3Coroutine Patterns and How to Use Them: Problems and Solutions Using Coroutines in a Modern Codebase
Use Them - CppCon 2023 3 makers.f.dev@gmail.comOutline • Motivation • Overview • Patterns • Lifetime • Exceptions • RAII • Synchronization • Conclusions Francesco Zoffoli - Coroutine Patterns and foo()_1 Executor foo()_2Patterns • Lifetime • Exceptions • RAII • Synchronization Francesco Zoffoli - Coroutine Patterns and How to Use Them - CppCon 2023 17Lifetime Francesco Zoffoli - Coroutine Patterns Patterns and How to Use Them - CppCon 2023 18Lifetime • Lots of worries • Use Structured Concurrency[1] • ASAN works great Francesco Zoffoli - Coroutine Patterns and How to Use Them - CppCon 2023 190 码力 | 70 页 | 1.45 MB | 5 月前3The Roles of Symmetry And Orthogonality In Design
hints (until C++17) // ... Bar b; constructing destructing Object Lifetime Lifetime ends when destructor call starts Lifetime begins when initialization is complete allocating deallocating Bar::Bar() when accessing an object outside its lifetime // ... Bar b; constructing destructing Object Lifetime Lifetime ends when destructor call starts Lifetime begins when initialization is complete Static (program-begin…program-end) • Dynamic (new…delete) • Thread (thread-begin…thread-end) Object Lifetime Begins when BOTH of: 1. Storage is obtained 2. Initialization is complete Ends when EITHER of:0 码力 | 151 页 | 3.20 MB | 5 月前3Code Analysis++
Improve software quality ● Lower developer frustration ● Avoid UBLanguageLanguage helps! – ● Lifetime safety: http://wg21.link/ p1179 ○ Owner & Pointer ○ Built-in compiler check ○ Current LLVM helps! – ● Lifetime safety: http://wg21.link/p1179 ● std::source_location: since C++20 ○ To avoid macro-styled logging and tracing ○ Part of bigger effortLanguage helps! – ● Lifetime safety: http://wg21 ]], [[post ]], [[assert ]] ○ MVP discussion, ignore or check&abort modesLanguage helps! – ● Lifetime safety: http://wg21.link/p1179 ● std::source_location: since C++20 ● Contracts: http://wg210 码力 | 61 页 | 2.70 MB | 5 月前3Rust 语言学习笔记
................................................................................. 37 3.3.1 隐式 lifetime ....................................................................... 37 3.4 高级所有权 ........ 分析:借用者 x 的生命周期是资源所有者 a 的生命周期的子集。但 是 x 的生命周期在第一个 }时结束并销毁,在接下来的 println! 中再 次访问便会发生严重的错误。 3.3.1 隐式 lifetime 我们经常会遇到参数或者返回值为引用类型的函数: fn foo(x: &str) -> &str { x } foo 函数仅仅接受一个 &str 类型的参数(x 为对某个 中较短的那个生命周期结束之前保持有效。 要推导 Lifetime 是否合法,先明确两点: 1.输出值(也称为返回值)依赖哪些输入值 2.输入值的 Lifetime 大于或等于(可能依赖的输出值)的 Lifetime (准确来 说:子集,而不是大于或等于) Lifetime 推导公式: 当输出值 R 依赖输入值 X Y Z ...,当且仅当输出值的 Lifetime 为所有输入值的 Lifetime 交集的子集时,生命周期合法。0 码力 | 117 页 | 2.24 MB | 1 年前32020: The Year of Sanitizers?
@ciura_victor - 2020: The Year of Sanitizers? 👉24 Lifetime profile v1.0 https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/Lifetime.pdf This is important because it turns out to be easy default behavior. CppCoreGuidelines Lifetime safety: Preventing common dangling 2020 Victor Ciura | @ciura_victor - 2020: The Year of Sanitizers?25 Lifetime profile v1.0 https://github.com/is blob/master/docs/Lifetime.pdf CppCoreGuidelines void example() { std::string_view sv = std::string("dangling"); // A std::cout << sv; } clang -Wlifetime Experimental Lifetime safety: Preventing0 码力 | 135 页 | 27.77 MB | 5 月前3Compile-Time Validation
if (ptrs_depth[action.self_id] < ptrs_depth[action.other_id]) { return validation_error(i, lifetime_too_short{}); } } Validate that a pointer in an outer scope isn't pointing to a value in an { meta::reflect_value(k) }))){ ++k; } define_class(r, {}); return k; } };Circle – Lifetime Safety Circle is a C++ compiler by Sean Baxter with many language extensions. Many operations int* ptr = &index; printf("%d", *ptr); } }Circle – Lifetime Safety Adds lifetime annotation: T^ is a borrow reference. /a is a lifetime annotation. auto get_max/(a)(int^/a x, int^/a y) safe ->0 码力 | 137 页 | 1.70 MB | 5 月前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100