引用 | 編輯
z1022001
2011-01-20 12:33 |
樓主
▼ |
||
x0
想請問一下new 和 new const 兩者在效能上有差嗎? 如果有差的話 請問: 複製程式 #define A 0 #define B 1 #define C 2 #define MAX 3 new const name[MAX][] = { "name_A", "name_B", "name_C" { 複製程式 new i = 0 while( i < MAX ) { client_print( 0, print_chat, "[%s]", name[i] ) i++ } 輸出為: [name_A] [name_B] [name_C] 該怎麼改寫,才能在只改變 A, B, C 的define的值 就讓輸出 NAME 字串的順序跟著改變? x0
|
引用 | 編輯
a7811311622
2011-01-20 17:21 |
2樓
▲ ▼ |
下面是引用 z1022001 於 2011-01-20 12:33 發表的 關於源碼的優化: 呃…我說…「define」和「const」都是「定值」吧… 既然想變化就改成宣告「變數」不就得了…? x0 |
引用 | 編輯
a7811311622
2011-01-20 19:05 |
4樓
▲ |
下面是引用 z1022001 於 2011-01-20 18:07 發表的 : 效能有沒有差異我是沒查過… 不過會用「const」主要是希望指定的內容是不會被改變的…例如: 複製程式 new const weapon_classname[][] = { "", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10", "weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550", "weapon_galil", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249", "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552", "weapon_ak47", "weapon_knife", "weapon_p90" } 你總不會希望「weapon_classname」裡的任何一個字串中途變成其他內容吧… 這樣有可能造成武器ID值和該位置的武器實體名稱對照不上… 更慘的話武器ID值對應位置是無意義字串或是空字串… x1 |