89 questions
0
votes
2
answers
121
views
What does Raw pointer metadata mean in Rust?
I wonder why the metadata of the raw pointer in box is (), but the metadata of sized, which is stored on the stack, is the metadata of a slice ([T]), which is described as the number of items and has ...
2
votes
1
answer
107
views
Recasting Variadic Arguments from void** Array in C++
I'm working on a project where I need to convert variadic arguments into a void** array, pass them to a lambda function, and then correctly cast them back to their original types for use in a custom ...
1
vote
3
answers
108
views
Assign member before constructor run
I have a wired problem and don't find a way around it. It looks like the following:
class MyClass : public BaseClass {
public:
MyClass() : BaseClass(initializeResource())
{ }
~MyClass() {
...
1
vote
1
answer
619
views
Idiomatic usage of Arc in C FFI
I want to implement a FFI for C-Code which calls Functions written in Rust and stores results in Rust-objects for later use.
The Rust-Code returns references to objects as Arc<T> where T equals ...
1
vote
1
answer
215
views
subrange of a fixed size buffer c++ avoiding raw pointers
I am working on some code which is a state machine, and different classes are responsible for different kind of task, all of which are acquiring data. Upon completing the data acquisition, the data ...
0
votes
1
answer
168
views
Why don't raw pointer in vector become nullptr? [duplicate]
I want to dynamically-allocate an int and then push the corresponding pointer into the vector. After use, I set to nullptr all the elements of vector, but original pointer doesn't become nullptr.
Why ...
1
vote
1
answer
152
views
Is moving the target of a raw Pointer safe in rust
I'm creating a bidirectional graph in rust and the parent pointer are an obvious problem with the rust borrowing rules so I used raw pointers which are in theory safe since the parent owns the child ...
2
votes
1
answer
161
views
How to cast a &T to a &Wrapper(T)?
I have this snippet of code showcasing a simplification of my problem.
struct Wrapper1(u32);
impl Wrapper1 {
fn inner(&self) -> &u32 {
&self.0
}
}
struct Wrapper2(u32);...
0
votes
1
answer
68
views
Trying to learn and understand the behaviour of unsafe rust within thread execution. Can someone explain what I might done wrong here?
use std::sync::Arc;
use std::sync::atomic::{AtomicPtr, Ordering};
use std::thread;
fn main() {
let mut arr = vec![1,2,3];
let ptr = &mut arr as *mut Vec<i32>;
println!("...
-2
votes
1
answer
278
views
Why Rust's raw pointer can access function and some parts of fields' information of a struct variable out of scope?
I want to use Rust raw pointer like *const to reproduce the security problem of use after free, but when I use the raw pointer to access fields or call the function of a freed struct variable, there's ...
1
vote
1
answer
220
views
How do I model a non-owning view on some resource (not itself managed via shared_ptr), if not via raw pointer?
std::unique_ptr is for exclusive ownership.
std::shared_ptr is for shared ownership.
So it looks like a raw pointer is left just the job of being a non-owning pointer, at least in good code.
But if I ...
1
vote
0
answers
436
views
How to I assign a value to a raw pointer at the module level in Rust?
If I have a raw pointer that is defined at the module level, how do I assign another value to it?
struct SomeStruct {
field: u8,
}
// create a module level null raw pointer
static mut ...
0
votes
1
answer
102
views
Convert c++98 code to new c++17 code when using std::vector of pointers
i dont what to manage or less as i can manage raw pointers note in the example i have to delete the object before removeing it from the vector i want to avoid it it here and later
what will be good ...
0
votes
2
answers
1k
views
Pointer to a self-defined struct in Rust with raw pointers
I am implementing some structures to be used with search algorithms. These structures are to be stored in a Linked List during the execution of a program. After struggling a bit with integrating ...
2
votes
2
answers
494
views
Can I pass a std::vector<std::unique_ptr<T>> as a vector of raw pointer without extra allocations?
Suppose I have the following function:
void sum(const std::vector<int*>& input) {
return ... ; // the sum
}
I store a vector of int pointers somewhere
...
std::vector<std::unique_ptr&...