MapPhysicalMemory
int MapPhysicalMemory (unsigned int physicalAddress, unsigned int numberOfBytes, void *ptrToMappedAddress, int *handle);
Purpose
![]() |
Note This function is obsolete and always returns an error code of 0, which indicates failure. |
Maps a physical address to a pointer that you can use in your program like any other C pointer.
For example, you can read or write an area of physical memory by incrementing the pointer after each access.
In cases where you cannot transfer all your data at once, MapPhysicalMemory provides better performance than ReadFromPhysicalMemory or WriteToPhysicalMemory. There is a significant performance penalty to mapping and unmapping physical memory. If you call ReadFromPhysicalMemory or WriteToPhysicalMemory on each access, you map and unmap the memory each time.
When you no longer need the pointer, call UnMapPhysicalMemory on the handle mapHandle returns.
![]() |
Note MapPhysicalMemory requires the LabWindows/CVI low-level support driver. LabWindows/CVI loads the driver at startup if it is on disk. You can check whether LabWindows/CVI loaded the driver at startup by calling CVILowLevelSupportDriverLoaded. The low-level support driver is not supported on 64-bit systems. Only applications running with administrator privileges on 32-bit systems can load the low-level support driver. |
![]() |
Note MapPhysicalMemory does not check the validity of the physical address. |
Example Code
int physAddr = 0xB000;
int numBytes = 0x1000;
int *physMemPtr;
int mapHandle;
int data, i;
if ( ! MapPhysicalMemory (physAddr, numBytes, &physMemPtr, &mapHandle))
{
/* report error */
}
else
{
for (i=0; i < numBytes/sizeof(int); i++)
{
/* <determine data to write> */
*physMemPtr++ = data;
}
UnMapPhysicalMemory (mapHandle);
}
Parameters
Input | ||
Name | Type | Description |
physicalAddress | unsigned int | Physical address to map into user memory. No restrictions exist on the address, which can be below or above 1 MB. |
numberOfBytes | unsigned int | Number of bytes of physical memory to map. |
Output | ||
Name | Type | Description |
ptrToMappedAddress | void * | The mapped physical address. Pass a pointer by reference as this parameter. |
handle | int | The handle that you pass to the UnMapPhysicalMemory function to unmap the physical memory. |
Return Value
Name | Type | Description | ||||||
status | int | Indicates whether the function succeeded.
|
Additional Information
Library: Utility Library
Include file: utility.h
LabWindows/CVI compatibility: LabWindows/CVI 5.0 and later