It could write like this
also like this
Which one is better?why.Or what is the difference between them?
I find some trouble when .data is replaced by .data?
.data?
hWinMain dd ?
hInstance dd ?
.data
szExitApp db 'Exit?',0
szCaption db 'made by ekin',0
szFormatdb '%s%s',0
also like this
.data
hWinMain dd ?
hInstance dd ?
szExitApp db 'Exit?',0
szCaption db 'made by ekin',0
szFormat db '%s%s',0
Which one is better?why.Or what is the difference between them?
I find some trouble when .data is replaced by .data?
Well this question has been asked numerous times... and the answer seems
to boil down to this :
.DATA = a variable data "segment" that is used for pre-initialized elements.
.DATA? = a variable data "segment" that is used for un-initialized elements.
.DATA = increases the size of the final executable due to compilation.
.DATA? = does not increase the size of the final executable. The "segment" is
dynamically allocated at run-time of the executable.
.DATA = has faster access to the data elements especially in smaller applications
due to the caching nature of the modern architecture.
.DATA? = has no such advantage.
The one is not better than the other - but have different and more appropriate
uses.
Draakie
Well seems I might have got it wrong then - "RE:Faster access" - I read it someplace
and thought it was fact and did'nt bother to check. Strangely beieng a little bit
stubborn - see attached. 80% of the time .data and .data? performs the same -
20 % of the time .data is faster..... note diffirences on application restart.....does'nt
seem like complete :"bullshit" ...... although it might just be.
to boil down to this :
.DATA = a variable data "segment" that is used for pre-initialized elements.
.DATA? = a variable data "segment" that is used for un-initialized elements.
.DATA = increases the size of the final executable due to compilation.
.DATA? = does not increase the size of the final executable. The "segment" is
dynamically allocated at run-time of the executable.
.DATA = has faster access to the data elements especially in smaller applications
due to the caching nature of the modern architecture.
.DATA? = has no such advantage.
The one is not better than the other - but have different and more appropriate
uses.
Draakie
Well seems I might have got it wrong then - "RE:Faster access" - I read it someplace
and thought it was fact and did'nt bother to check. Strangely beieng a little bit
stubborn - see attached. 80% of the time .data and .data? performs the same -
20 % of the time .data is faster..... note diffirences on application restart.....does'nt
seem like complete :"bullshit" ...... although it might just be.
.DATA = has faster access to the data elements especially in smaller applications
due to the caching nature of the modern architecture.
.DATA? = has no such advantage.
Where did this come from? I would have thought they were the same as far as access goes, but would like
to be set straight...
.DATA = increases the size of the final executable due to compilation.
.DATA? = does not increase the size of the final executable. The "segment" is
dynamically allocated at run-time of the executable.
.DATA = has faster access to the data elements especially in smaller applications
due to the caching nature of the modern architecture.
.DATA? = has no such advantage.
Well AFAIK, Data Segments and other user application segments are all dynamically created by the Windows OS as soon as the application's main process is created. These will be placed in the application's LDT and then the LDT's information will be placed in TSS at Byte#96. The only difference .DATA and .DATA? have is that the former can contain initialized values but the latter can't. I don't think there is any more difference between these two.
DATA1 dw 1234 ;one word
DATA2 dw ? ;basically a dynamic buffer
If you write a .com file the other way round
DATA2 dw ?
DATA1 dw 1234
and assemble it
The program will start with DATA1 intact, then DATA2 will overwrite/corrupt DATA1 when you add anything to DATA2 because it has no memory writing/block limitations.
DATA2 railroads straight over the top of DATA1.
The ? means its dynamic.
DATA2 dw ? ;basically a dynamic buffer
If you write a .com file the other way round
DATA2 dw ?
DATA1 dw 1234
and assemble it
The program will start with DATA1 intact, then DATA2 will overwrite/corrupt DATA1 when you add anything to DATA2 because it has no memory writing/block limitations.
DATA2 railroads straight over the top of DATA1.
The ? means its dynamic.
:)Thank you!So the .const have the same attributes of the .data?
.const = increases the size of the final executable due to compilation AND
has faster access to the data elements especially in smaller applications due
to the caching nature of the modern architecture
Am i right?
.data is the place to put your initialized data, such as initialized struct, etc.
.data? is the place to put your uninitialized data, such as variables(hInstance), buffers, etc.
.const is the place to put your constants, such as strings that dont change, float constants, etc. , and no .const is not for equates :)
when you link your PE file
.data data is present in the file and the raw size of PE-.data section in your PE file matches the size of all your initialized data. The virtual size of PE-.data section in your PE file is the sum of .data and .data? aligned to PAGE_SIZE.
.const from source usually goes to PE-.rdata section between IAT and import api strings and has characteristics of ReadOnly.
just load your pe in a Pe Editor
and the part of "faster access" is not true. Access will only be faster if you don't mix your code and data.
.data? is the place to put your uninitialized data, such as variables(hInstance), buffers, etc.
.const is the place to put your constants, such as strings that dont change, float constants, etc. , and no .const is not for equates :)
when you link your PE file
.data data is present in the file and the raw size of PE-.data section in your PE file matches the size of all your initialized data. The virtual size of PE-.data section in your PE file is the sum of .data and .data? aligned to PAGE_SIZE.
.const from source usually goes to PE-.rdata section between IAT and import api strings and has characteristics of ReadOnly.
just load your pe in a Pe Editor
and the part of "faster access" is not true. Access will only be faster if you don't mix your code and data.
Which one is better?why.Or what is the difference between them?
I find some trouble when .data is replaced by .data?
At any rate, this type of simple information has been covered again and again. As I suggest to all beginners, please use the search function or read Iczelion's Tutorials prior to asking questions... you'll find that you learn much more that way ;)
DATA1 dw 1234 ;one word
DATA2 dw ? ;basically a dynamic buffer
If you write a .com file the other way round
DATA2 dw ?
DATA1 dw 1234
and assemble it
The program will start with DATA1 intact, then DATA2 will overwrite/corrupt DATA1 when you add anything to DATA2 because it has no memory writing/block limitations.
DATA2 railroads straight over the top of DATA1.
The ? means its dynamic.
Wrong - the '?' only means it's uninitialized data, which (as mentioned previously) means that, for file formats that support it, they can be part of the program's memory image without taking up disk space.
If you use '?' data in file formats without this support (or, say, in the .data section instead of the .data? section), you'll end up having disk usage anyway.
As for the speed issue, drizz covered it as well. Keep your data and code 4kb apart or suffer.
8)Thanks!I will read Iczelion's Tutorials!Even it is a tough work.