- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 154字
- 2021-07-02 23:07:26
The stack frame
The stack frame is a term you may have come across. It is the amount of memory allocated to a function, which is used to store all of the local variables and function parameters. In the following snippet, the stack frame will be large enough to store the two int values and the single float32 type:
fn main() { let a = 10; let b = 20; let pi = 3.14f32; }
Once main has exited, the stack frame allocated on entry will be released. The beauty of both the allocation and deallocation is that they are carried out without the user needing to do anything. The amount of memory can also be computed ahead of time, as the compiler knows which local variables are in use. This, again, gives a speed increase.
For every positive, there is a downside: the values stored only exist for the lifetime of the method.
推薦閱讀
- 深度實踐OpenStack:基于Python的OpenStack組件開發
- C++程序設計(第3版)
- Python自然語言處理實戰:核心技術與算法
- Computer Vision for the Web
- 編寫高質量代碼:改善Python程序的91個建議
- PyTorch自然語言處理入門與實戰
- x86匯編語言:從實模式到保護模式(第2版)
- Instant QlikView 11 Application Development
- 手把手教你學C語言
- JavaScript入門經典
- Julia高性能科學計算(第2版)
- 低代碼平臺開發實踐:基于React
- Integrating Facebook iOS SDK with Your Application
- 速學Python:程序設計從入門到進階
- Python圖形化編程(微課版)