Map caching

Map caching is designed to improve the interactive character of ECRTP by eliminating the processing time associated with opening and closing maps. The user is able to specify that maps will be cached in memory and to specify the maximum number of maps that will be cached. The user is also able to load specific maps into memory before running the ECRTP.

The user is able to specify that a map will stay open, using the –mx <maximum number of cached maps> switch. A separate switch is required for each map that will remain open. This functionality is available through both the ECRTP .dll and the ECRTP executable. For the ECRTP executable, maps will stay open only until the executable is finished. For the ECRTP .dll, the maps will stay open until the user explicitly closes them. The open maps are maintained in a structure in memory, with the mapname as the index key. An API allows a pointer (to the array of maps stored in memory) to be passed back to the calling program.

The user specifies the maximum number of maps that will remain open. If no maximum is specified, the default is 0 maps. As a result, if the user does not explicitly set a maximum number of maps, the ECRTP will not cache maps in memory. If the maximum number of maps is reached and the user specifies that a new map is to remain open, the program uses an algorithm to determine the least frequently used map of the maps that are currently open and replace that map with the new map. There is no upper limit to the maximum number of maps except that imposed by memory.

The user passes in the map name, and the function returns a “-1” if the map is not found and a “1” if the map is found and removed. This functionality is not applicable for the ECRTP executable because it automatically frees all maps in memory when it is finished, and consequently, ignores any -xf switch.

The user may use UTILCONTMAP and UTILMAPNAME to decide which map to free from memory with the FREEMAPNAME() API.

extern "C" DLLEXPORT int WINAPI UTILCOUNTMAP(int *mapMaxLoad, 
int *mapLoaded);extern "C" DLLEXPORT int WINAPI UTILMAPNAME(int mapPosition, char
   *mapName, int mapNameBufSize);                                                          

There are two return parameters for UTILCOUNTMAP. The first return parameter is int *mapMaxLoad. This is the maximum number of maps that can be loaded into memory. This value is set by the initial -mx N parameter on the command line API (for example, OUTBOUNDRUNCmd, OUTRun, INBOUNDRUNCmd, or INRun). The second return parameter is int *mapLoaded. This is the number of maps that have actually been loaded into memory.

The API function returns zero (success) as long as the original -mx N switch is used to allow multiple map processing. The API function returns -1 if there is no -mx switch or there was a -mx 0 switch.

There are two input parameters for UTILMAPNAME. The first input parameter is int mapPosition. The valid values are 0 to maximum number of maps. The first map is loaded at index zero and the second map is loaded at index position 1, and so forth. The second input parameter is int mapNameBufSize. This input parameter provides the maximum length of the parameter String mapName.

The output parameter for UTILMAPNAME is char * mapName which specifies the name of the map loaded at mapPosition index.

UTLIMAPNAME returns a zero (success) and the name of the map at position mapPosition in the mapName return parameter. If no map was loaded at position, mapPosition or the map name size was greater than mapNameBufSize then a -1 for failure is returned.

Using the LOADMAP API, the user is able to load map(s) into memory before the ECRTP is run. The user passes in the map directory, map name, and map direction, as well as the maximum number of maps that can be cached at one time. (The maximum number passed to this DLL must be the same maximum number that is specified in the -mx <maximum number of maps> switch on the ECRTP command line.

The arguments for the LOADMAP API are shown below:

LOADMAP(LPSTR dir_path, LPSTR name, int map_dir, int
MulMaps)
dir_path -- directory where map file store in disk. 
				such as "c:\\temp\\850IN"

name -- name of map file without extension file name
			such as "T850IN" not "T850IN.MAP"

map_dir -- 				0 means INBOUND, 
				1 means OUTBOUND 

MulMaps--			how many maps are allowed to save in memory.
			It should have same value as -mx switch when
			the run ECRTP

The LOADMAP API returns one of the following four error/success codes:

Neither -xf nor -mx is case-sensitive.