简体   繁体   中英

Why local variables are stored in stack memory for java

我只想知道局部变量是存储在栈内存中的

The storage duration of local variables follow the LIFO(last in first out)principle.So using a stack -a LIFO data structure for allocating with LIFO storage is natural.Also the allocation and de-allocation of the memory is handled automatically unlike the heap.

Note that some local variables are stored in register also.This is since access to register is faster than access to the stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM