|
-
October 19th, 2004, 02:53 AM
#1
what is top size of memory-mapped file?
Hi,guys...
I had sucessfully used memory-mapped file on small file many times...but yesterday when i used it on 729M file,it failed...the code is following...what should i do to corret the code...thx in advance.
Code:
HANDLE hFile = ::CreateFile (pFileName, GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
if ( hFile == INVALID_HANDLE_VALUE ) {
return FALSE;
}
DWORD dwSizeHi;
m_dwFileSize = ::GetFileSize(hFile, &dwSizeHi);
HANDLE hFileMapping = ::CreateFileMapping(hFile, NULL, PAGE_READONLY,0, 0, NULL);
if ( hFileMapping == NULL ) {
::CloseHandle(hFile);
return FALSE;
}
m_p = (LPBYTE)::MapViewOfFile(hFileMapping, FILE_MAP_READ,
0, 0, 0);
::CloseHandle(hFile);
::CloseHandle(hFileMapping);
if ( m_p == NULL ) {
DWORD dwError = GetLastError();
return FALSE;
}
pFileName was file name,
i mapped the 729M file...m_p == NULL was TRUE;then dwError was 8,it stand for no enough memory...BTW.My memory size was 256M; OS was Windows 2000 server.
Regards,
Ephemera
Last edited by ephemera; October 19th, 2004 at 02:55 AM.
-
October 21st, 2004, 03:41 AM
#2
Re: what is top size of memory-mapped file?
The size of your physical RAM should not be a problem. A disk file mapped read-only or read-write behaves a bit like an additional swap file. According to
http://support.microsoft.com/default...b;EN-US;125713
only the available address space of the process (largest contiguous block of it) is the limitaion. On W2K it is 2Gb. I believe the server edition could be configured to allow 3Gb per process.
Does "paging" through the file fit easily into your application? What I mean is instead mapping the whole file into the memory space of your process to use the last 3 parameters of MapViewOfFile to map a portion of it, then unmap it and map the next portion etc.
Boris Karadjov
Brainbench MVP for Visual C++
http://www.brainbench.com/
-
October 23rd, 2004, 09:11 AM
#3
Re: what is top size of memory-mapped file?
Boris, are you saying that one can create a 2Gb big view of 2Gb+ file ? Why does the MapViewOfFile fail then ?
Last edited by Amn; October 23rd, 2004 at 09:14 AM.
-
October 26th, 2004, 03:19 AM
#4
Re: what is top size of memory-mapped file?
I cannot guarantee about creating a 2Gb view because part of your process's address space is used by executable modules and data. But yes, you can create a view smaller than the size of the file. See the MSDN description of the parameters dwFileOffsetHigh, dwFileOffsetLow, and dwNumberOfBytesToMap. In the code from your first post dwNumberOfBytesToMap is 0, which means map the whole file.
Boris Karadjov
Brainbench MVP for Visual C++
http://www.brainbench.com/
-
October 26th, 2004, 04:26 AM
#5
Re: what is top size of memory-mapped file?
Then I guess it makes sense to view the whole map at once, because kernel paging is significantly faster than swapping the views. Make a view which is say, 512Mb high (is that within limits of available process space ?) ?
-
October 26th, 2004, 11:03 AM
#6
Re: what is top size of memory-mapped file?
 Originally Posted by Amn
Why does the MapViewOfFile fail then ?
This can always be answered by calling 'GetLastError()'...
-
October 26th, 2004, 12:00 PM
#7
Re: what is top size of memory-mapped file?
It was. It returns "Not enough memory"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|