久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

С++ 中的字符串文字是在靜態(tài)內(nèi)存中創(chuàng)建的嗎?

Is a string literal in С++ created in static memory?(С++ 中的字符串文字是在靜態(tài)內(nèi)存中創(chuàng)建的嗎?)
本文介紹了С++ 中的字符串文字是在靜態(tài)內(nèi)存中創(chuàng)建的嗎?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

c++ 中的字符串字面量是否在靜態(tài)內(nèi)存中創(chuàng)建并僅在程序退出時(shí)銷毀?

Is a string literal in c++ created in static memory and destroyed only when the program exits?

推薦答案

它的創(chuàng)建位置實(shí)際上是編譯器編寫者的實(shí)現(xiàn)決定.最有可能的是,字符串文字將存儲(chǔ)在內(nèi)存的只讀段中,因?yàn)樗鼈冇肋h(yuǎn)不會(huì)改變.

Where it's created is an implementation decision by the compiler writer, really. Most likely, string literals will be stored in read-only segments of memory since they never change.

在過去的編譯器時(shí)代,您曾經(jīng)擁有像這些文字這樣的靜態(tài)數(shù)據(jù),以及全局但可變的數(shù)據(jù).這些被存儲(chǔ)在 TEXT(代碼)段和 DATA(初始化數(shù)據(jù))段中.

In the old compiler days, you used to have static data like these literals, and global but changeable data. These were stored in the TEXT (code) segment and DATA (initialised data) segment.

即使你有像 char *x = "hello"; 這樣的代碼,hello 字符串本身也存儲(chǔ)在只讀內(nèi)存中,而變量 x 位于堆棧上(或者在可寫內(nèi)存中的其他地方,如果它是全局的).x 只是設(shè)置為 hello 字符串的地址.這允許各種棘手的事情,例如字符串折疊,以便無效選項(xiàng)"(0x1000)和有效選項(xiàng)"(0x1002)可以使用相同的內(nèi)存塊,如下所示:

Even when you have code like char *x = "hello";, the hello string itself is stored in read-only memory while the variable x is on the stack (or elsewhere in writeable memory if it's a global). x just gets set to the address of the hello string. This allows all sorts of tricky things like string folding, so that "invalid option" (0x1000) and "valid option" (0x1002) can use the same memory block as follows:

+-> plus:0   1   2   3   4   5   6   7   8   9   A   B   C   D   E
|      +---+---+---+---+---+---+---+---+---+---+---+---+---+---+----+
0x1000 | i | n | v | a | l | i | d |   | o | p | t | i | o | n | 

主站蜘蛛池模板:
亚洲综合99
|
av毛片|
中文字幕av网
|
一级特黄在线
|
午夜天堂精品久久久久
|
欧美日韩视频网站
|
久久精品在线
|
国产ts一区|
国产三级|
影音先锋欧美资源
|
中文字幕国产高清
|
av毛片在线播放
|
国产精品成人在线观看
|
四虎影音
|
在线91|
国产乱码精品一区二区三区五月婷
|
91在线视频国产
|
国产精品久久久久久久免费大片
|
美国一级毛片a
|
九九看片
|
九九热这里只有精品在线观看
|
亚洲欧美日韩精品久久亚洲区
|
国产高清自拍视频在线观看
|
中文字幕日韩欧美一区二区三区
|
日韩亚洲视频
|
亚洲在线高清
|
九九视频网
|
aaa一区
|
久久久久久亚洲精品
|
a成人|
日韩在线国产
|
毛片片|
久久九精品
|
国产精品69久久久久水密桃
|
久久国产综合
|
亚洲一区 中文字幕
|
热99|
国产欧美一区二区精品忘忧草
|
日韩一区二区三区在线观看
|
久久久久久久成人
|
欧美h版|