Hi,

I want to use this within a Dll-function:

jmp @F
data DWORD 0,0
text BYTE "Hello",0
@@:


I can read the variables and use them, but I cannot write to it. Program crashes.
How can I write to them without having a datasegment ?

Greetings,
Nordwind64
Posted on 2004-06-25 16:16:14 by Nordwind64
Hello,

You're not allowed (by default) to write to code section. (aka .text).

To enable writing to this section you must provide this switch to the linker:



/SECTION:SectionName,ERW


Replace SectionName with .text if you want to enable write flag to code section.

Neitsa.
Posted on 2004-06-25 16:31:53 by Neitsa
Hi Neitsa,

work fine, thank you !!!
Does the dll-code now works slower in this mode ?

Greetings,
Nordwind64
Posted on 2004-06-26 15:56:05 by Nordwind64
It will not work slower because you can write to it, but it may go slower if you do write to it!
There are two level 1 caches on the processor - data and code - and usually they will never contain the same information (data sections & code sections being different sections of memory), when they do, if you modify the data section this effectively makes part of the code cache invalid but the processor does not know this until its too late! This will stall the pipeline, with all the associated penalties.

It is best if at all possible to avoid this, there are few situations where you must embed data in the code on modern systems because they have so much memory, wasting a couple of hundred bytes with one extra data section doesn't cost much.

Mirno
Posted on 2004-06-27 06:00:50 by Mirno
Thank you Mirno !!!

Greetings,
Nordwind64
Posted on 2004-06-27 06:23:56 by Nordwind64
Hi all :)

Wouldn't this technique cause the code section at the DLL to be copied into each process that loads the library, like the data section? (As opposed to having a single copy of the code, and multiple copies of the data).
Posted on 2004-06-27 10:10:08 by QvasiModo
Thank you, QvasiModo (or QuasiModo ?) !

It works ok for me :-)

Greetings,
Nordwind64
Posted on 2004-06-29 14:31:50 by Nordwind64