久久久久久久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精品久久久
|
午夜噜噜噜
|
做a视频
|
午夜精品久久久久久久星辰影院
|
日韩精品一区二区三区中文在线
|
激情91|
日日摸夜夜添夜夜添精品视频
|
综合九九
|
一区二区三区四区国产
|
国产精品久久久久久网站
|
97超碰人人
|
免费久久精品视频
|
一级片视频免费
|
国产精品一区一区三区
|
一级片在线播放
|
91在线精品一区二区
|
国产精品一区二区三区免费观看
|
日韩免费在线观看视频
|
伊人精品在线
|
毛片在线免费播放
|
三区四区在线观看
|
亚洲精品视频免费观看
|
天堂中文在线观看
|
久久久人成影片一区二区三区
|
视频一区 亚洲
|
午夜精品久久久久久久久久久久久
|
一区二区三区免费
|
狠狠躁天天躁夜夜躁婷婷老牛影视
|
亚洲手机视频在线
|
成人免费观看视频
|
欧美精品二区
|
欧美日韩在线免费观看
|
中文一区二区
|
99tv|
精品国产乱码久久久久久蜜臀
|
成人啊啊啊
|
精品欧美一区二区中文字幕视频
|
激情毛片
|