MapViewOfFileEx - valid lpBaseAddress

In response to a question about matching non-contiguous file blocks to contiguous memory here , one respondent suggested that I use VirtualAllocEx () with MEM_RESERVE to set a "safe" value for the final (lpBaseAddress) parameter for MapViewOfFileEx ().

Further research showed that this approach results in a MapViewofFileEx () error with error 487: "Try to access an invalid address." On the MSDN page :

"There is no other memory allocation in the area used for matching, including using the VirtualAlloc or VirtualAllocEx function to reserve memory."

Although the documentation may be considered ambiguous regarding valid call sequences, experimentation suggests that it is not permissible to reserve memory for MapViewOfFileEx () using VirtualAllocEx ().

On the Internet, I found examples with hard-coded values ​​- an example :

#define BASE_MEM     (VOID*)0x01000000

...

hMap = MapViewOfFileEx( hFile, FILE_MAP_WRITE, 0, 0, 0, BASE_MEM );

To me this seems inadequate and unreliable ... It is not clear to me why this address is safe or how many blocks can be safely displayed there. It seems even more shaky, given that I need my solution to work in the context of other distributions ... and that I need my source to compile and work in 32 and 64-bit contexts.

, , - - MapViewOfFileEx .

+5
3

, . , VirtualAlloc ( MEM_RESERVE), , ( MapViewOfFileEx) VirtualFree ( MEM_RELEASE). . ( VirtualAlloc) MapViewOfFileEx.

+2

, . ( - ), .

, . , , . .

64- , , , .

MSDN:

( ), , . .

, " " (, ), .

:

lpBaseAddress , , . , 32- .

, , : . , .

, :

, , - - MapViewOfFileEx .

, . (, , DLL, DLL ..).

0

, , .

Of the MapViewOfFileEx Documents, the pointer you specify is "A pointer to a memory address in the address space of the calling process where the mapping starts. Must be a multiple of the system memory allocation granularity, or the function does not work."

the memory allocation dimension is 64K , so you cannot map disparate 4K pages from a file to neighboring 4K pages in virtual memory.

0
source

All Articles