# memory map question

## Recommended Posts

i want to accces my file by means of memory mapping, everything works correctly, but the files created are getting bigger then 4 gigabyte so i need to adress those as well(not mapping the entire file into memory just offseting a filepointer and start from there). the msdn documentation gives me this LPVOID WINAPI MapViewOfFile( HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap ); dwFileOffsetHigh [in] A high-order DWORD of the file offset where the view begins. dwFileOffsetLow [in] A low-order DWORD of the file offset where the view is to begin. The combination of the high and low offsets must specify an offset within the file mapping. They must also match the memory allocation granularity of the system. That is, the offset must be a multiple of the allocation granularity. To obtain the memory allocation granularity of the system, use the GetSystemInfo function, which fills in the members of a SYSTEM_INFO structure. right now i'm only using dwFileOffsetLow as starting adress, but this is only works for files less then 4 gb. how dow i specify also the high value how can i specify both offsetlow and offsethigh when my fileoffset is stored as a 'long long' regards Paul

##### Share on other sites
If your file offset is stored in a long long, then simply shift the bits:

void SplitOffset  ( long long p_FileOffset  , DWORD&    p_OffsetLow  , DWORD&    p_OffsetHigh  ){  // Low offset is taken by blanking out the "most significant" 32 bits  p_OffsetLow = (DWORD)(p_FileOffset & 0x00000000FFFFFFFF);  // High offset is taken by shifting the value 32 bits to the right  p_OffsetHigh = (DWORD)(p_FileOffset >> 32);}

##### Share on other sites
Quote:
 Original post by El GrecoIf your file offset is stored in a long long, then simply shift the bits:*** Source Snippet Removed ***

Although it may well make more sense to wrap the Windows API call directly:

LPVOID WINAPI MapViewOfFile(HANDLE fileMapper, DWORD desiredAccess, unsigned long long fileOffset, SIZE_T amountToMap) {  return MapViewOfFile(fileMapper, desiredAccess,                       static_cast<DWORD>(fileOffset >> 32),                       // Masking off the high bits is implicit when you cast                       // to a smaller integral type, when the types are unsigned.                       static_cast<DWORD>(fileOffset), amountToMap);}

##### Share on other sites
Alternately, you can use the LARGE_INTEGER structure that gives you the high and low DWORDS. LARGE_INTEGER is used by Windows in a number of places, such as GetFileSizeEx(), which is making me wonder how you're getting your file size in the first place if you're having this problem.

##### Share on other sites
Quote:
 Original post by SiCraneAlternately, you can use the LARGE_INTEGER structure that gives you the high and low DWORDS. LARGE_INTEGER is used by Windows in a number of places, such as GetFileSizeEx(), which is making me wonder how you're getting your file size in the first place if you're having this problem.

i'm used to java, and just started learn to program c++, and i want my code to be as os neutral as possible, but i've figured it out already, bit shifting the index solved the problem thanks all

Paul

##### Share on other sites
Quote:
 Original post by PaulHolverdai'm used to java, and just started learn to program c++, and i want my code to be as os neutral as possible, but i've figured it out already, bit shifting the index solved the problem thanks allPaul

MapViewOfFile is as non-portable and as OS specific as it gets...

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627671
• Total Posts
2978550

• 11
• 10
• 10
• 12
• 22