Hi!
It's known that some constants and variables are needed only for initialization.
Class name and Window name are good examples.
After creating window those strings are useless.
It's not a big problem in the case of only two strings.
But if you have many such initializing constants it's good idea
to think about usig that space for other purposes.
To do that we can use well-known LABEL stuff:



dwVar1 LABEL DWORD
szClassName db "Wind"
dwVar2 LABEL DWORD
db "ow C"
dwVar3 LABEL DWORD
db "lass", 0


Works without any problem, but looks, IMHO, very ugly and difficult to change.
So, bugs are welcome here.

I use other method for such things.


DISCARDABLE_DATA_START MACRO
;; define begining of data to discard
@DiscardableDataStart LABEL BYTE
ENDM

DISCARDABLE_DATA_END MACRO
;; calculate size of data to discard
@DiscardableDataSize = $ - @DiscardableDataStart
ENDM

SUBSTITUTION_DATA_START MACRO
;; set location counter to begining of data to discard
ORG $ - @DiscardableDataSize
ENDM

SUBSTITUTE MACRO sub:REQ, typ:REQ, num:=<1>
local over
sub LABEL typ
;; take into account size of defined variable
@DiscardableDataSize = @DiscardableDataSize - (sizeof sub)*num
;; report error if Substitution is more than Discardable
IF @DiscardableDataSize LT 0
over TEXTEQU %(0 - @DiscardableDataSize)
% .ERR <Size of discardable data was exceeded by substitution data for over bytes>
ENDIF
;; point location counter to next memory available
ORG $ + (sizeof sub)*num
ENDM

SUBSTITUTION_DATA_END MACRO
local available
IF @DiscardableDataSize GT 0
;; report how much available data left
available TEXTEQU %@DiscardableDataSize
% ECHO *** available bytes are left to substitute. ***
;; and take the rest into account
ORG $ + @DiscardableDataSize
ENDIF
ENDM


With the help of above macros i can write such code:


.data
DISCARDABLE_DATA_START
szClassName db "Window Class", 0
DISCARDABLE_DATA_END

SUBSTITUTION_DATA_START
SUBSTITUTE dwVar1, DWORD
SUBSTITUTE dwVar2, DWORD
SUBSTITUTE dwVar3, DWORD
SUBSTITUTION_DATA_END


The szClassName and dwVar1 here reference to the same memory address.
szClassName is used at window creating but later will be substituted by value of dwVar1, dwVar2, dwVar3.
See full example in attach.

I find it's much more clear and easy to make changes.
But don't sure is it the best way.
May be someone has discovered better method.
How do you do that?
Posted on 2002-07-10 06:08:39 by Four-F
with fasm you do it simply:



szClassName db "Window Class", 0

virtual at szClassName
dwVar1 dd ?
dwVar2 dd ?
dwVar3 dd ?
end virtual
Posted on 2002-07-10 06:22:39 by Tomasz Grysztar
Four-F, we no longer live in the world with 640KB of memory and 10Mhz CPUs.
Posted on 2002-07-10 13:05:32 by comrade
comrade, waste not, want not. :grin: :grin:
Posted on 2002-07-10 13:14:13 by bitRAKE
We're now living in a world with stack frames and virtual memory.

When building an NT driver, it was a practice to put initialization code into a separate read-only block of pages. After the paging system discards these "initialization" pages, they are never reloaded. (Unless, of course, you unload and restart the driver.)

Also, LOCAL (stack) variables are discarded when you leave a PROC. The next PROC you invoke will automatically reuse that space for LOCAL variables.
Posted on 2002-07-10 15:54:44 by tenkey
comrade & tenkey, thanx for answering. :(
But you answered the question that i haven't asked.

I know about 640KB/10Mhz/IDATA/ICODE etc...
I'm writing some spying tool.
My goal to use as few as possible of remote process resources.
It's ring3, and i can't say to OS to discard something.

You may be know about EliCZ's excellent asm/system stuff that is full of such juggles.
Question for what?... If you find no sense to do such trick don't do it.
But i merely asked that i asked. No more.
Sorry for some rudeness.
Posted on 2002-07-11 03:05:58 by Four-F
Tvoi post kogbuto bi cherez russkiy->english translator proshol
Posted on 2002-07-11 03:58:57 by comrade
Four-F,

Thanks for some examples that use lesser used dirctives/operators... ORG and $.
Posted on 2002-07-11 04:57:21 by ThoughtCriminal
comrade:
Tvoi post kogbuto bi cherez russkiy->english translator proshol

Eto ti k chemu?
I know my english is ugly.
Also my russian is not good.
Hope my asm is perfect. ;)

ThoughtCriminal:
Thanks for some examples that use lesser used dirctives/operators... ORG and $.

Thanx.
Posted on 2002-07-11 06:25:44 by Four-F
Hi Four-F!

Good idea, nice macro. I will use it, if you please.

Thanx ;-)
Posted on 2002-07-11 06:59:07 by Andycar
Hi, Andy!
Can't find time to complete my ListView/TreeView/etc... macros.
Posted on 2002-07-11 09:31:57 by Four-F
Russkiy! Klass! Teper 3 takih na etoi message board: ia, ti i Dmitry. :)
Posted on 2002-07-11 14:34:44 by comrade
Four-F, look for documentation of the COMMON segment directive - it can also be used to accomplish this double use of memory. It is a little trickier. :)
Posted on 2002-07-11 15:19:18 by bitRAKE
You cant forget that if you declare, say for example 300 bytes of data in your data section, and then use say for example 160 bytes of it again (For a total of 560 bytes), it does not matter how much you use that memory over and over again, you are still effectivly going to be using the whole 4096 byte memory page.
Posted on 2002-07-11 23:55:22 by huh

Russkiy! Klass! Teper 3 takih na etoi message board: ia, ti i Dmitry. :)


Privet,
Ya dumayu, tut gorazdo bolshe, chem 'na troih' russkih sobralos', prosto ostal'nie sidyat' sebe tihonechko :grin:
Posted on 2002-07-12 03:00:28 by Andycar
You cant forget that if you declare....


Of course i know about page granularity.
My ex is only very very simple explanation of principle.
It depends on you to use it properly.

For russian guys:
Please, don't forget that the language of this board is NOT russian!
Posted on 2002-07-12 03:57:23 by Four-F
bitRAKE:
Four-F, look for documentation of the COMMON segment directive - it can also be used to accomplish this double use of memory. It is a little trickier.


Yes, seems to be useful, but i couldn't make it overlap DATA segment.
Also seems to me that segment being overlapped by COMMON segment can contain only discardable data.
So, you can't mix discardable/nondiscardable data in one seg.
But can't prove it to myself because of the reason above.
If you have some workable ex, please throw it at me. Thanx.
Posted on 2002-07-12 05:34:54 by Four-F
Have to build separate object files, and the object file with initial data has to be linked in last. I should create an example - it has been a long time since I used this. Also, all the references to the initial data are specified external public.
Posted on 2002-07-12 05:51:41 by bitRAKE
Okey, 4 teper - ia, AndyCar, Four-F, Dmitry.
Posted on 2002-07-12 12:52:16 by comrade