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

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.

主站蜘蛛池模板: 巴楚县| 砚山县| 缙云县| 略阳县| 股票| 新营市| 刚察县| 连州市| 德化县| 大化| 毕节市| 鹤峰县| 黑河市| 兴和县| 巴中市| 榆林市| 句容市| 建德市| 黄大仙区| 安龙县| 成安县| 永靖县| 济阳县| 光山县| 平泉县| 封丘县| 汉阴县| 新民市| 奉新县| 区。| 若尔盖县| 东辽县| 南澳县| 滦南县| 广饶县| 济宁市| 丰都县| 清涧县| 南召县| 阳春市| 井研县|