Re: Virtual Address Space
- Posted by Kat <gertie at PELL.NET> Nov 10, 2000
- 418 views
On 10 Nov 2000, at 13:29, Al Getz wrote: > I ran across something peculiar when working with multiple > threads, i was wondering if anyone had any ideas on this: > > for example: > > In the following two programs, program1 allocates a single > byte in memory, fills the byte with the number 2, and then > calls a second program passing the address of the byte. It > then waits for user to type a key before freeing the original > byte allocated. > The called program, program2, attempts to read the original byte > using the address passed from the first program. The address is > printed out byte by byte in both programs in order to verify that > the address was passed successfully. <snip> > The peculiar thing here is that although the byte cant be read > successfully in the second program, it doesnt generate an exception > or any error of any kind. Just quietly returns the wrong value > every single time. > > Any other thoughts or comments on this? Are you trying that multithreading idea i mentioned a month or more ago? One of the things i mentioned, that are required, is that the memory be locked, so that the OS can't page the programs/data around. I don't mean allocated, i mean truely locked down by the OS. It's "lock_memory" in dos32, i don't know what it is in win32lib. If you can grab the memory, i recommend memory windoze doesn't use, like maybe a small section of dos/driver/card memory between 640K and 1meg. In the olden days, some of us used a few bytes of non-displaying screen memory. Alternatively, you might be surprised by how fast you can write a short file to disk and have the 2nd program read it, i have written loops before that read the file back out and deleted it before the OS's disk cache ever actually put it on the disk. It stayed in memory the whole time, and speed at the time was not a problem. YMMV. I had suggested a small ini file to hold those memory addys you mentioned, so you can pass them back and forth between multiple threads, handy when the size of the reserved memory must be changed, or when you want to map a variable *into* another, as opposed to *on top of*. Or you can use DDE, in windoze, if you can figure out how, i can't. I use it in mirc a lot (it's a built-in function), it saves on error msgs too, and the state of the handles is query-able, etc.. And as usual, socks is attractive, especially in threading, even with the overhead, cause you can then thread on separate puters on a LAN, on different OSs even, if you have threads that last any significant amount of time. Lemme know if you want me to be quiet.. Kat