I have a problem with this code:
Invoke CreateFileMapping, 0, 0, 4, 0, MySize, 0

I use it to allocate memory (well, quite unconvetionally ok)
It seems to work well from Win98 to WinXP, but it returns 0 on Win95
I am doing something wrong? is there some way to fix this?
Posted on 2003-02-22 12:55:17 by DZA
Nay. Use the appropiate API to allocate memory. Use GlobalAlloc or HeapAlloc (though i think HeapAlloc is better)
Posted on 2003-02-22 21:29:38 by roticv
Well, since you didn't make any tests to find it out yourself (which you always should
try before posting here!!), I experimented with it and found out the obvious (D'oh!):
You have to pass an open file-handle to CreateFileMapping for it to work (at least in
Windows 95).
Anyways, I'm wondering why your approach should work on the 'newer' windows
versions and not on the older ones (W95) ... because it used to be vice versa! :rolleyes:

You should give us more info on what you're trying to do with that mem.
However, if you're in search for high memory, use VirtualAlloc with MEM_TOP_DOWN.

aweX <-
Posted on 2003-02-23 01:02:49 by aweX
You cant use MEM_TOP_DOWN in win95... and one reason why you would want to allocate memory using file maps on win9x is because file maps are shared memory =)

Also you do not need to pass an open file handle on windows 95, but you do have to pass INVALID_HANDLE_VALUE which equates to -1.


which equates to...

invoke CreateFileMapping, -1, 0, 4, 0, MySize, 0
Posted on 2003-02-23 09:42:41 by BubbaFate

You cant use MEM_TOP_DOWN in win95...

I know that, but it is a documented flag, so I mentioned it for
completeness, since I wasn't sure what he is actually trying to do.

one reason why you would want to allocate memory using file maps on win9x is because file maps are shared memory =)

Ah, nice workaround, but why not use the simple method:

invoke VirtualAlloc, NULL, {size}, MEM_SHARED, {page attributes}

Oh, maybe you just weren't aware of:

MEM_SHARED EQU 08000000h

aweX <-
Posted on 2003-02-23 10:05:36 by aweX
I do not have access to my Windows 95 machine at the moment so I cannot verify this, but I am 99% sure MEM_SHARED does not work on Windows 95 because the API is written specifically to fail if you use that flag.
Posted on 2003-02-23 10:17:35 by BubbaFate
Nevermind your right.
Posted on 2003-02-23 10:39:22 by BubbaFate
I know ...
Because I don't really like presenting things as facts if I didn't try them
beforehand... I'm using this for years.

The few instructions you posted were just some standard flag-analysing
code. I also have them in my (Win95) VirtualAlloc. Hmm, why did you edit
it out? You have had stripped one important instruction in your disasm
(marked red):

:BFF8002C F7C700000008 test edi, 08000000
:BFF80035 740D jz BFF80044
[color=red]:BFF80037 C745FC00000680 mov [ebp-04], 80060000[/color]
:BFF8003E 81E7FFFFFFF7 and edi, F7FFFFFF
:BFF80044 81E7FFFFEFFF and edi, FFEFFFFF

Look at the red line and you will see that it stores some info in
only when MEM_SHARED is used, and then the bits are masked out. It only
masks MEM_TOP_DOWN out unconditionally so it can easily check
for the rest with simple cmp instructions, where test would be inappropriate.

Next time just try :grin:

aweX <-
Posted on 2003-02-23 23:23:12 by aweX
I don't need the memory shared, neither I care of speed or the allocation to be at some higher memory area (lol). I have some special reasons why I needed alternate winall ways of allocating memory..I know of some other unconventional memory allocation methods, but they are not winall (like using ord_01, int 2e )
I use these winall methods to alloc memory:HeapAlloc, VirtualAlloc, LocalAlloc, GlobalAlloc, CreateFileMappingA.
If anyone knows any other method of allocating memory winall compatible, pls let me know:D
Thanks Bubba Fate for the great help..passing an invalid handle worked just fine on Win95 also.
Posted on 2003-02-24 09:42:39 by DZA