본문 바로가기

Rust

Rust - 개념 및 C/C++과의 차이

반응형

Rust_Logo

Rust. C++의 대체 시스템 프로그래밍 언어!

  1. 공통 :
    1. 최소 runtime
    2. Garbage collector X
  2. 차이 :
    1. Ownership system
    2. Type system : 컴파일러는 잘못된 형식의 변수에 어떤 작업도 적용되지 않게 보장
    3. 메모리 안정성 보장(without Garbage collector).
      1. c
        1. segmentation faults와 undefined behavior 고려하여 개발해야 함. (cognitive overhead)
        2. 스마트포인터 개념이 도입되었지만 이는 한계가 완전한 메모리 안정 보장이 되지 않음.
      2. Rust
        1. Borrow checker : 동일한 값을 동시에 변경할 수 없도록 하여 스레드 보안을 보장
          1. ownership 관리 : 스코프 내에서 변경가능한 참조자를 하나만 두게 하는듯 함.-> Garbage collector없이 메모리 안정성을 보장할 수 있게 함.
          2. 포인터가 항상 유효한 메모리를 참조하도록 한다.
    4. 패키지 매니저 : cargo vs conan/vcpkg
    5. macro system : Declarative & Procedural

ℹ️Unsafe Rust

UnsafeRust_Logo

  • 저수준의 시스템 프로그래밍, ex) 운영체제와 직접 상호작용

The only things that are different in Unsafe Rust are that you can:

  • Dereference raw pointers
  • Call unsafe functions (including C functions, compiler intrinsics, and > - the raw allocator)
  • Implement unsafe traits
  • Mutate statics
  • Access fields of unions
반응형