官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 远安县| 犍为县| 鹿邑县| 罗江县| 温宿县| 襄汾县| 万载县| 齐河县| 崇明县| 常熟市| 福州市| 锡林浩特市| 望江县| 平阳县| 井陉县| 麻栗坡县| 九龙坡区| 青冈县| 临潭县| 道真| 布尔津县| 云安县| 阳泉市| 南宁市| 玉田县| 阳城县| 博爱县| 云浮市| 象州县| 灵武市| 信阳市| 庆云县| 兴业县| 汉沽区| 凤冈县| 安溪县| 新昌县| 南开区| 连山| 当雄县| 吉水县|