[英]Where is global variables like $_GLOBAL , $_POST etc stored?
當我參加面試時,面試官問我這個問題。 他們使用堆,堆棧等內存。我用Google搜索但我沒有得到任何明確的答案。
好吧,既然你標記了C
,我就會從那開始。
在C運行時,全局變量存儲在兩個位置之一; 數據段或BSS段。 確定特定變量屬於哪一個的方式是它是否已初始化。
global (and static) variables go inside the . 全局(和靜態)變量進入 。
global (and static) variables go inside the . 全局(和靜態)變量進入 。
在視覺上,整個運行時看起來像這樣:
_______
| Text |
|_______|
| Data | <-- Initialized globals / statics
|_______|
| BSS | <-- Uninitialized globals / statics (basically a bunch of 0s)
|_______|
| |
| Stack |
|_______|
| |
| Heap |
|_______|
and the , which are created at runtime, global variables exist as part of your program's executable image file ( a.out
, foobar.exe
). 與在運行時創建的和變量不同,全局變量作為程序的可執行映像文件( a.out
, foobar.exe
)的一部分存在。
內部$_POST
的值在php_auto_globals_create_post()
中創建,並通過PG(http_globals)[TRACK_VARS_POST]
,這只是一種引用http_globals
。
上述http_globals
的定義告訴我們它是一個zval *
元素數組,每個$_POST
, $_GET
, $_COOKIE
等一個(數組也存儲在zval
容器中)。
分配zval
是通過ALLOC_ZVAL()
,它調用以下函數:
malloc()
函數在堆上分配內存,因此答案是堆 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.