Hi ya-all,

I would like to know how to allocate a part of memory in windows globally for all instances of my proggy to acess - and only my proggy.

i am currently using CoTaskMemAlloc that gives me a pointer to the allocated memmory.

I would like to stick as closly to WinAPI calls as possible.

Oh by-the-way any routine like ZeroMemory (VC++) that can clear the contents of the allocated memory for me,
i hate loops... (no real trace debugger availible. Using Olly, i guess i got lazy while using VC++)

Thanx
Posted on 2004-04-15 19:47:09 by Black iCE
memory mapped files as long as you do ring3... start by trying to map it, if it doesn't succed, create it.
Posted on 2004-04-15 20:01:52 by f0dder
CreateFileMapping will open if its already created, and create otherwise
Posted on 2004-04-15 20:06:57 by comrade
The Question abou ZeroMemory Resolved : RtlZeroMemory!!!

The other, well... idealy i would like to generate the data on the fly cause the data is crutcial for my app. if i read it in from a file or memory mapping it then i might encounter unmarked bad sectors ect. and i need a fast acess to it.

the data will never change, and always follows a pattern. total required size is 6316032 bytes.
Posted on 2004-04-15 20:52:22 by Black iCE
why do u use api for zeroing memory when u are using assembly especially?
Posted on 2004-04-15 21:19:07 by comrade
Maybe some special buffer allocation with zeroing memory.
Posted on 2004-04-16 04:46:05 by Vortex
If you want global memory between multiple programs, file mapping is your only choice. Use INVALID_HANDLE_VALUE instead of a regular file handle, that way it's backed up by the paging file - and is, in effect, just a global piece of memory. Note that it's not global in the sense that you can just pass the memory pointer around - you will have to use OpenFileMapping in other processes.

If you only need to share memory between instances of *one* application, you could use a shared PE section instead. But for a 6 meg buffer, I would prefer the dynamic approach.

Even a "rep stosd" should be faster than a call to RtlZeroMemory, and there's even faster ways to do it - I don't expect your buffer zeroing is a critical piece of code, though, so rep stosd (or even calling RtlZeroMemory) is an okay choice.

Note that sharing memory between processes can be a bit tricky - if you only have read-only access to the shared memory after it's been generated, that does make things a bit easier, but you have to consider the possibility of lauching two instances of the app nearly simultaneously...
Posted on 2004-04-16 08:36:59 by f0dder
OK, i have tried using CreateFileMapping and it fails...
[6mb wrong, 8Mb - sorry my miscalculation]

invoke CreateFileMapping,INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,80h,NULL,ADDR szLookupTable

szLookupTable db "BitFusion.LookupTable",0
and eax is returned zero. i cant trace to this location in my progg and Olly is REALY startin to get on my bad side.

I initically wanted a worker thread to on "instance" to generate the code, but looking @ the documentation of F0dder's proposal, it looks simpler and it has the ability to tell me if i already created the buffer.

Any1 able to tell me why my call fails.
Posted on 2004-04-16 17:41:10 by Black iCE
another thing, the data goes as follows....

0
1 0
2 1 0
3 3 1 0
4 6 4 1 0
5 10 10 5 1 0
6 15 20 15 6 1
7 21 35 35 21 7

this is arranged in columbs and rows. i have an implementation for it in a memory block. {it is a lookup table for many purposes. Example :Lotto.... 46 total possible numbers and 6 gets drawn, how many posible combinations are there ? Remember every number only occurs once.} But for me it is a lookup table to use for bit to bit data compression on an idependant platform {video, audio and execution code holds the same *weight*}

The reason for this table is say we have 1024 availible spaces and require 256 of those space to be occupied... generating the numerical representation of this sequence will *even in asm* take approx 3 days or more {full exec time} and this is for 1 line of code.

Hence a dirivative of the generation routine, using the numerics that will cause an impact upon the result will yeald a bell curve table that can be used to determine the numerical number of the senario and vice versa - hence fast compression on a simple bit platform.
Posted on 2004-04-16 18:19:26 by Black iCE
Umm, you do realize you're asking for around 512 gigs of memory, right? :). If you want an 8meg buffer, pass 0 for dwMaximumSizeHigh and 0x800000 for dwMaximumSizeLow.



invoke CreateFileMapping, INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 0800000h, ADDR szLookupTable


...that should probably help a bit :)

Sorry it took me so long to answer, but I was working on some driver code that behaved weirdly (until I realized it was because of a unregister failure etc and I had to do a reboot - sigh).
Posted on 2004-04-16 22:32:04 by f0dder
Oops, sorry bout the mistake! THANX F0dder!!!

i feel like such an ass, typing the code out without actually looking at it.
Posted on 2004-04-16 22:38:54 by Black iCE
Don't worry, we all do that from time to time. The most obvious bugs can be the hardest to find...
Posted on 2004-04-16 22:40:18 by f0dder
Hey F0dder, do you know where i can perhaps get an ASM Reference. Like all the acronym (operation) listings and their effect upon the registers.... you see i am @ work and i just say lost most of my asm programming doc's and now i need to get it back. {Yahoo yealded no goot results}
Posted on 2004-04-16 22:45:05 by Black iCE
I think fasm has a good list of the instructions, www.flatassembler.net . Thomas has a little stuff in his win32asm tutor, www.madwizard.org . And of course, the intel stuff: http://www.intel.com/cd/ids/developer/asmo-na/eng/microprocessors/ia32/pentium4/resources/reference/index.htm .
Posted on 2004-04-16 22:50:33 by f0dder
Thank you again F0dder.

{i feel that i am going to start saying that i great deal more in this form....}
Posted on 2004-04-16 22:59:50 by Black iCE