FIND YOUR NEXT FEW LINES

Results for “owner”

Small, practical examples. Search by task or narrow things down below.

36 snippets foundClear filters
RustThreads & shared ownership

Borrow local data in a scoped thread

Borrow local data in a scoped thread in a complete Rust program using the standard library.

Rust✓ Tested
C++Ownership & optional values

Capture configuration by value in a callable

C++: A value capture retains the value from lambda creation even if the original variable changes later.

C++✓ Tested
CDynamic memory & ownership

Check an array allocation size before multiplying

C: Compare the requested element count against SIZE_MAX divided by element size.

C✓ Tested
CDynamic memory & ownership

Clear an owning pointer after releasing its allocation

C: Assigning NULL helps prevent accidental reuse through the same variable.

C✓ Tested
CDynamic memory & ownership

Create an independent copy of a byte buffer

C: Allocate the exact byte length and copy only after checking the result.

C✓ Tested
CDynamic memory & ownership

Grow an allocation without losing it on failure

C: Assign realloc to a temporary pointer so the original allocation remains available if growth fails.

C✓ Tested
CDynamic memory & ownership

Initialize a byte buffer to zero

C: memset initializes each byte to the chosen unsigned-char value.

C✓ Tested
RustThreads & shared ownership

Initialize shared data once

Initialize shared data once in a complete Rust program using the standard library.

Rust✓ Tested
RustThreads & shared ownership

Join a worker thread and read its result

Join a worker thread and read its result in a complete Rust program using the standard library.

Rust✓ Tested
RustThreads & shared ownership

Move owned data into a worker

Move owned data into a worker in a complete Rust program using the standard library.

Rust✓ Tested
C++Ownership & optional values

Own one dynamically allocated value with unique_ptr

C++: make_unique allocates a value whose lifetime is tied to its owning smart pointer.

C++✓ Tested
RustThreads & shared ownership

Protect shared mutable state with a mutex

Protect shared mutable state with a mutex in a complete Rust program using the standard library.

Rust✓ Tested