ntgbk2 wrote:
根據微軟的介紹,Rust語言具有很高的記憶體安全性,對比C++,可以大幅減少不安全的子例程。
簡單講, 就是所有程式碼已經編譯在程式裡面, 不需要執行時函式庫,
所以不必call 其他 procedure, 不必配置記憶體, 也不用釋放記憶體,
所以速度增加, 減少出錯, 這可以理解,
但是節省記憶體? 這是怎麼回事?
應該是程式碼很肥大, 很佔記憶體才對啊! 這其中有甚麼誤會嗎?
---------------------------------
為何選擇 Rust?
高效能
Rust 不僅速度驚人,而且節省記憶體。由於不需要執行時函式庫或垃圾回收機制,Rust 可以加速高效能需求的服務、執行在嵌入式裝置,並且輕鬆地與其他語言整合。
https://www.rust-lang.org/zh-TW
..................
sansen wrote:
https://www.rust-lang.org/zh-TW/learn
這裡有教學, 非常用心, 甚麼都沒有裝, 也可以在網頁上的"遊樂場",
顯示程式執行的結果(左半邊原始程式, 右半邊執行結果)
要先安裝 Visual Studio C++ Build tools , 要勾選 C++,
再安裝rust 才能正確執行,
裡面有各種教學, 語法類似 C++, 教材很簡單,
如果不想要看教材, 也可以看例子學習各種語法, 很容易入門
編一個程式顯示 Hello World!, 要160KB
試了下 線上網站,
似乎也沒多精簡,
160 KB 也很肥.
以下是 線上網站 自動產生的 Hello, world!
--------------- Standard Error ---------------
Compiling playground v0.0.1 (/playground)
warning: due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
warning: ignoring --out-dir flag due to -o flag
warning: `playground` (bin "playground") generated 2 warnings
Finished release [optimized] target(s) in 0.92s
--------------- Standard Output ---------------
--------------- Result ---------------
std::sys_common::backtrace::__rust_begin_short_backtrace:
pushq %rax
callq *%rdi
#APP
#NO_APP
popq %rax
retq
std::rt::lang_start:
pushq %rax
movl %ecx, %r8d
movq %rdx, %rcx
movq %rsi, %rdx
movq %rdi, (%rsp)
leaq .L__unnamed_1(%rip), %rsi
movq %rsp, %rdi
callq *std::rt::lang_start_internal@GOTPCREL(%rip)
popq %rcx
retq
std::rt::lang_start::{{closure}}:
pushq %rax
movq (%rdi), %rdi
callq std::sys_common::backtrace::__rust_begin_short_backtrace
xorl %eax, %eax
popq %rcx
retq
core::ops::function::FnOnce::call_once{{vtable.shim}}:
pushq %rax
movq (%rdi), %rdi
callq std::sys_common::backtrace::__rust_begin_short_backtrace
xorl %eax, %eax
popq %rcx
retq
core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>:
retq
playground::main:
subq $56, %rsp
leaq .L__unnamed_2(%rip), %rax
movq %rax, 24(%rsp)
movq $1, 32(%rsp)
movq $0, 8(%rsp)
leaq .L__unnamed_3(%rip), %rax
movq %rax, 40(%rsp)
movq $0, 48(%rsp)
leaq 8(%rsp), %rdi
callq *std::io::stdio::_print@GOTPCREL(%rip)
addq $56, %rsp
retq
main:
pushq %rax
movq %rsi, %rcx
movslq %edi, %rdx
leaq playground::main(%rip), %rax
movq %rax, (%rsp)
leaq .L__unnamed_1(%rip), %rsi
movq %rsp, %rdi
xorl %r8d, %r8d
callq *std::rt::lang_start_internal@GOTPCREL(%rip)
popq %rcx
retq
.L__unnamed_1:
.quad core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>
.asciz "\b\000\000\000\000\000\000\000\b\000\000\000\000\000\000"
.quad core::ops::function::FnOnce::call_once{{vtable.shim}}
.quad std::rt::lang_start::{{closure}}
.quad std::rt::lang_start::{{closure}}
.L__unnamed_3:
.L__unnamed_4:
.ascii "Hello, world!\n"
.L__unnamed_2:
.quad .L__unnamed_4
.asciz "\016\000\000\000\000\000\000"
</std::rt::lang_start<()></std::rt::lang_start<()>
內文搜尋

X