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

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.

主站蜘蛛池模板: 翁源县| 驻马店市| 大足县| 托克逊县| 陇西县| 怀柔区| 瓦房店市| 铁岭县| 申扎县| 金溪县| 邢台市| 阿拉尔市| 分宜县| 江城| 荥经县| 嘉定区| 浠水县| 山西省| 西畴县| 南陵县| 江油市| 磐石市| 鹤山市| 九龙坡区| 中山市| 青河县| 舞阳县| 霍城县| 迁西县| 高邮市| 双辽市| 华安县| 分宜县| 调兵山市| 竹北市| 北宁市| 青岛市| 潜江市| 双辽市| 尉氏县| 大丰市|