Link to home
Start Free TrialLog in
Avatar of jtm111
jtm111

asked on

Memory Mapping function MapViewOfFile parameters

I am learning how to memory map a large file...

I can map the entire file to a character buffer as follows just fine using the following call:


lpMMFile = (char *) MapViewOfFile (hInMap,
                                  FILE_MAP_READ,
                                  0,
                                  0,
                                  0);

Parameter 3 is the upper DWORD of the file offset
Parameter 4 is the lower DWORD
Parameter 5 is the number of bytes to transfer

When all three are set to 0, the whole file is mapped to lpMMFile. My program works just fine with these arguments.

I don't know how to use parameters 3 through 5 to select parts of the file into RAM.

Isn't a DWORD an 8 bit binary? I can't make it work.

For example, how would I select the contents starting at offset 20 and load 50 bytes into the char buffer?

My program displays (null).

Avatar of ua1zcl
ua1zcl

Minimal unit you can MapView is one page i.e. 4096 bytes
on Windows95/98 and similar systems.
A DWORD stands dor Double WORD and is a 32 bit integer. On Win9x systems the hihg dword of the file offset is supposed to be 0
The maximum length of file is 64 bit number.
Windows used to support only 32 bit variable, so in
order to represent every address in the system, U must use
2 DWORDS (hence, 64 bit variable).

Generally, Parameter 3 - the high-order DWORD of offset is 0.
Parameter 4 - will be the offset of the file

and parameter 5 - will be the size that U wanna map.

Good luck
ASKER CERTIFIED SOLUTION
Avatar of xutao
xutao

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtm111

ASKER

Thanks for the help everybody. I was using the DWORD correctly after all (casting hex values into DWORD), but I didn't know about the granularity issue so I was just flailing randomly. For benefit of others, I used the following code to get my offset and it seems to work:

LPSYSTEM_INFO si;
si = new SYSTEM_INFO;
GetSystemInfo (si);

DWORD dwOffsetLow = (DWORD) si->dwAllocationGranularity * (some integer multiplier);

Windows 98 also uses 65,536.