Note that there are some explanatory texts on larger screens.

plurals
  1. POMapViewOfFileEx - valid lpBaseAddress
    primarykey
    data
    text
    <p>In answer to a question about mapping non-contiguous blocks of files into contiguous memory, <a href="https://stackoverflow.com/questions/10454964/mapping-non-contiguous-blocks-from-a-file-into-contiguous-memory-addresses">here</a>, it was suggested by one respondent that I should use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887%28v=vs.85%29.aspx" rel="nofollow noreferrer">VirtualAllocEx</a>() with MEM_RESERVE in order to establish a 'safe' value for the final (lpBaseAddress) parameter for <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366763%28v=vs.85%29.aspx" rel="nofollow noreferrer">MapViewOfFileEx</a>().</p> <p>Further investigation revealed that this approach causes MapViewofFileEx() to fail with error 487: "Attempt to access invalid address." <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366887%28v=vs.85%29.aspx" rel="nofollow noreferrer">The MSDN page says</a>:</p> <blockquote> <p>"No other memory allocation can take place in the region that is used for mapping, including the use of the VirtualAlloc or VirtualAllocEx function to reserve memory."</p> </blockquote> <p>While the documentation might be considered ambiguous with respect to valid sequences of calls, experimentation suggests that it is not valid to reserve memory for MapViewOfFileEx() using VirtualAllocEx().</p> <p>On the web, I've found examples with hard-coded values - <a href="http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/proguide/ref/xumemex1.htm" rel="nofollow noreferrer">example</a>:</p> <pre><code>#define BASE_MEM (VOID*)0x01000000 </code></pre> <p>...</p> <pre><code>hMap = MapViewOfFileEx( hFile, FILE_MAP_WRITE, 0, 0, 0, BASE_MEM ); </code></pre> <p>To me, this seems inadequate and unreliable... It is far from clear to me why this address is safe, or how many blocks can be safely be mapped there. It seems even more shaky given that I need my solution to work in the context of other allocations... and that I need my source to compile and work in both 32 and 64 bit contexts.</p> <p>What I'd like to know is if there is <strong>any</strong> way to reliably reserve a pool of address space in order that - subsequently - it can be reliably used by MapViewOfFileEx to map blocks to explicit memory addresses.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload