I've a problem with FileMappings larger than 1 GB. I knew, that I cannot map files larger than 1 GB into memory (at least with Win95). So I tried to open the mapping, but map only potions of 512 MB, looping through the file. But this fails also! Is this feature "by design of windows"?
Posted on 2002-05-21 07:03:38 by beaster
CreateFileMapping out to work for any size (I tend to use 0,0 to map
the entire file). MapViewOfFile has restrictions due to the memory
layout windows uses (512 megs ought to be safe, I wouldn't ever
map more than that at one time). Do you UnmapViewOfFile and
do a new MapViewOfFile in your loop? That *ought* to work...
otherwise I suppose a lot of software would break :).

Also, unless you *need* "pointer access" to the file, consider using
readfile instead, as memory mapped files have considerable overhead.
Posted on 2002-05-21 09:44:15 by f0dder
I retried this with a small test code. You are right, CreateFileMapping works on a large file, but the mapping call to MapViewOfFile fails always, also the first one, no matter how many bytes to map.

I searched MS for this, but no comments, must be a limitation of (at least my Win95C) kernel.
Posted on 2002-05-23 04:37:33 by beaster
This sounds pretty weird! Can you reproduce the problem with a small code snippet?
Posted on 2002-05-23 07:13:26 by f0dder
I have tried this:
szFile:	db	"c:\stauraum\vid.mp2", 0

push 0
push 0
push offset szFile
call CreateFile
mov hFileMPEG, eax

push 0
push 0
push 0
push 0
push hfileMPEG
call CreateFileMapping
mov hMap, eax

push 1024
push 0
push 0
push hMap
call MapViewOfFile
the file is bytes. I have realized now a ReadFile version, CreateFile and ReadFile have no problems.
Posted on 2002-05-23 11:31:15 by beaster
I got Win95B... is there a Win95C upgrade... where can i find IT?
Posted on 2002-05-23 12:27:00 by cmax
I think there is no upgrade, MS released only the three different full-versions of Windows, called Win95A, Win95B, Win95C. The both last are also called OSR2 and OSR2.5, mainly with growing support for USB. C has also some Win98 features, like active desktop and of cause always the latest driver set.
Maybe there are some updates as stand alone downloads.
Posted on 2002-05-27 04:23:41 by beaster
When calling MapViewOfFile, win9x will commit this memory block (allocated in the shared memory region from 80000000-BFFFFFFF).
This region is also used by win16 dlls + heaps, shared win32 dlls+heaps (like kernel32.dll) and dpmi memory allocs. So possible reason for failure are:

- your swap file cannot be enlarged to fullfill the commit (or swapping has been turned off)
- win32 dlls are loaded in the shared region at "bad" addresses, say A0000000h. You can call VirtualQuery to check for the maximum "hole" in the shared region.
Posted on 2002-05-27 06:35:06 by japheth
there is absolutly no problem with files smaller than 1 GB, I can map them partially or at once, even 0.99 GByte large .vob files (from DVD). But as soon as the file is larger, mapping dont work anymore, also no smaller mappings (in my code snip: 1024 bytes)

Maybe windows tries to VirtualAlloc a block with the size of the whole file?
Posted on 2002-05-28 02:03:43 by beaster
Beaster, try passing 'limited sizes' to both CreateFileMapping and
MapViewOfFile. I think that the size passed to CreateFileMapping is
the max size you expect to map in at once, where with MapViewOfFile
it's the size you want to map currently.
Posted on 2002-05-28 05:34:03 by f0dder