Virtual Data ..
'?' sign is reserved for Virtual Uninitialized Data declarations:
[MyData: ? #500]
Will declare 500 uninitialized dWords that will not appear as as many zeros inside the dead file and, that is, will save disk space .
You cannot mix Uninitialized data and Initialized data inside the same Brackets set. RosAsm does 2 different computations for these 2 separate kinds of Data and 'pastes' this chunk after initialized data computations.
Virtual Data are virtually stored in write order, at the end of Data section. This way for doing this preserves from 01000 hexa memory alignment of an additional .BSS section. Alignment rules, between sets, are the same as the ones for other Data.
As opposed to previous versions, these Data are now zeroed at load time. You have no longer to initialize them at run time, as I previously recommended when zeros were expected.
Beginners: Of course, you will find it much easier to reserve memory for your tables this way, because Initialized and Uninitialized Data accesses are easier than Dynamic ones. For important memory requirements you MUST learn how to ask Win for dynamically allocated memory. Have a search in RosAsm source for 'VirtualAlloc' / 'VirtualFree'... which are the simpliest regular functions for memory management.
When to use '?' Data
Declaring one single dWord as uninitialized Data doesn't make any sense as there are very few chances this really decreases the file size, because of sections alignments. As well declaring it as '0' common Data.
Tables bigger than 01000 hexa are better declared as dynamic memory. Uninitialized Data are perfectly designed for tables, let us say, between 10 and 4000 octets. Typically, several hundreds '?' bytes tables will save memory consumption compared to 'VirtualAlloc' / 'VirtualFree', if we need them running , because several of these tables will be supposedly fit inside a same 01000 hexa memory chunk at run time.
If you are in need of a data table that should be available, as is, from PE upload to PE close, you can do it this way, what ever size it be (in the real world, this is quite uncommon).
So, as a whole, you have a lot of ways for memory management under Win32:
- Data
- Virtual Data
- Global/LocalAlloc
- VirtualAlloc
.... depending on each case... I never use Global/LocalAlloc because it requires a handle plus pointer management, plus calls to Global/localLock/Unlock. The advantage of these last functions, compared to the 'VirtualFunctions' simplicity is that they do not align on section boundary, and so forth preserve from spoiling memory. (I do not care of Memory spoiling in this case because I need memory either temporary or not in my own writings...).
~~~~~~~