What the heck is this? y: ~~~~~Foo
Rust for C++ programmers – part 4: unique pointers
31–40 of 99 posts
Re: Rust for C++ programmers – part 4: unique pointers
#32Re: Rust for C++ programmers – part 4: unique pointers
#33Earlier quoted context omitted.
I feel pretty good about it. For one, we have significantly better aliasing information than C++, and we use most of the guts, including all the optimizations and code generation, of a C++ compiler (clang/LLVM). There are also some optimizations around move semantics that are open to us but not for C++ as standardized. That said, there are definitely performance bugs that have yet to be fixed. But I would definitely…
How does one do intrinsics (SSE / AVX) in Rust - I guess they're just the exposed functions from emmintrin.h and the compiler calls them directly? How do you do ASM in Rust? Can you align memory in rust?
There's an asm! macro: http://static.rust-lang.org/doc/0.10/guide-unsafe.html#inlin...
> Can you align memory in rust?
I think that's an open problem for now, e.g. https://github.com/mozilla/rust/issues/4578
Re: Rust for C++ programmers – part 4: unique pointers
#34Earlier quoted context omitted.
> 1 - If memory management is a serious problem for the software you work on, I've never found the boost library lacking. A key feature of Rust is being memory safe by default without sacrificing too much performance. In C++ it's not really possible to be completely safe, and pretty much all real-world C++ I've seen doesn't even come close to that ideal, using raw pointers frequently; the result is that crashes can b…
> Most C++ code uses switch frequently, usually without taking advantage of fallthrough. I am not so sure about this. Thinking back on my uses of switch in C and C++, I am not able to remember using switch without taking advantage of fallthrough. Maybe I am just not a typical C++ programmer...
switch (x) {
case 0: case 1: foo(); break;
case 2: case 3: bar(); break;
default: baz();
}
in the form of match x {
0 | 1 => foo(),
2 | 3 => bar(),
_ => baz()
}
In any case, Rust's match is so much more powerful than switch, offering (nested) pattern matching like Haskell's `case`.Re: Rust for C++ programmers – part 4: unique pointers
#35Re: Rust for C++ programmers – part 4: unique pointers
#36I've been working C++ professionally for a couple of years and honestly I'm a huge fan - So I was excited to read about an alternative. After reading your 5 posts, I get the impression that RUST is mostly mildly useful syntactic sugar on top of C++. Here is my feedback: 1 - If memory management is a serious problem for the software you work on, I've never found the boost library lacking. This seems like the main sell…
As a developer that isn't working with C++, I'm finding memory management in C++ to be a nightmare and no amount of libraries can solve it.
Say you receive a pointer from somewhere. Is the referenced value allocated on the stack or on the heap? If allocated on the heap, do you need to free it yourself, or is it managed by whatever factory passed it to you? If you need to deallocate that value, is it safe doing so? Maybe another thread is using it right now. If you received it, but it should get deallocated by the factory that gave it to you, then how will the factory know that your copy is no longer in use? Maybe it's automatic, maybe you need to call some method, the only way to know is to read the docs or source-code very carefully for every third-party piece of code you interact with.
All of this is context that you have to keep in your head for everything you do. No matter how good you are, not matter how sane your practices are, it's easy to make accidental mistakes. I just reissued my SSL certificate, thanks to C++.
Yeah, for your own code you can use RAII, smart pointers, whatever is in boost these days and have consistent rules and policies for how allocation/deallocation happens. Yay! Still a nightmare.
Even if manageable, there's a general rule of thumb that if a C++ project doesn't have multiple conflicting ways of dealing with memory management and multiple String classes, then it's not mature enough.
Re: Rust for C++ programmers – part 4: unique pointers
#37I recently wondered whether it's possible to compile rust into a dll/so or whether there is a way to call rust from other languages (e.g. C, R, or ruby). All I found is that this isn't (easily?) possible because of rust's runtime. Is this true? If so, will it be possible to call rust from, e.g., C code? I'd like to have an alternative to c/c++ for writing native extensions for interpreted languages.
Re: Rust for C++ programmers – part 4: unique pointers
#38Earlier quoted context omitted.
How does one do intrinsics (SSE / AVX) in Rust - I guess they're just the exposed functions from emmintrin.h and the compiler calls them directly? How do you do ASM in Rust? Can you align memory in rust?
> How do you do ASM in Rust? There's an asm! macro: http://static.rust-lang.org/doc/0.10/guide-unsafe.html#inlin... > Can you align memory in rust? I think that's an open problem for now, e.g. https://github.com/mozilla/rust/issues/4578
Does Rust allow using memory allocated by specific external allocators? i.e. libnuma or something?
Re: Rust for C++ programmers – part 4: unique pointers
#39I've been working C++ professionally for a couple of years and honestly I'm a huge fan - So I was excited to read about an alternative. After reading your 5 posts, I get the impression that RUST is mostly mildly useful syntactic sugar on top of C++. Here is my feedback: 1 - If memory management is a serious problem for the software you work on, I've never found the boost library lacking. This seems like the main sell…
> If memory management is a serious problem for the software you work on, I've never found the boost library lacking. As a developer that isn't working with C++, I'm finding memory management in C++ to be a nightmare and no amount of libraries can solve it. Say you receive a pointer from somewhere. Is the referenced value allocated on the stack or on the heap? If allocated on the heap, do you need to free it yourself…
?
Re: Rust for C++ programmers – part 4: unique pointers
#40I've been working C++ professionally for a couple of years and honestly I'm a huge fan - So I was excited to read about an alternative. After reading your 5 posts, I get the impression that RUST is mostly mildly useful syntactic sugar on top of C++. Here is my feedback: 1 - If memory management is a serious problem for the software you work on, I've never found the boost library lacking. This seems like the main sell…
> If memory management is a serious problem for the software you work on, I've never found the boost library lacking. As a developer that isn't working with C++, I'm finding memory management in C++ to be a nightmare and no amount of libraries can solve it. Say you receive a pointer from somewhere. Is the referenced value allocated on the stack or on the heap? If allocated on the heap, do you need to free it yourself…
There is an overhead to having to think and plan for it, but in my experience of using it for things ranging from realtime systems through to high performance, multi-threaded image processing and rendering applications, at least if you're in control of most of the code and it's pretty good code, it's not really an issue.