home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
disk
/
misc
/
filecache
/
filecache.doc
< prev
next >
Wrap
Text File
|
1995-02-27
|
9KB
|
276 lines
FileCache Server V1.00
(C) 1992,93 Christophe PASSUELLO
--------------------------------
INTRODUCTION
------------
FileCache is a task used as a server, its goal is to cache includes files
in memory for compilers and assemblers, with this you can greatly speed up
compilations.
When you ask to the server to load a file it will check before if the file
is in cache, in this case le file doesn't need to be loaded from disk, else
the file will be load from disk and put in the cache. If there not enough
place to put the file in cache the Least Recently Used files will be removed
from cache to make place for the new file (LRU algorythm). So every next
compilation or assembly includes file will be read from memory instead of
disk.
Each file loaded in cache is put in a single block of memory, at return of
a load request the server will return address of the block for the file and
its size so you can do parsing directly in the block of memory, so no more
buffer and Read() call overhead.
Any task can use the server through its public port.
DISCLAIMER
----------
The author is not responsible of any damages resulting of FileCache use.
INSTALLING THE SERVER
---------------------
Before any program can use the server, you must install it: You install it
by running it.
1> run FileCache -mXX : XX is the size max of cache in KBytes.
Memory allocation is dynamic, so the memory used by the cache is only
the memory used by the files in cache. You can define a bigger cache
than you really need, to be sure that all files will be in cache and
no memory will be wasted. (for example a cache of 300 KBytes is enough
for most compilations).
Once installed, you can flush the cache, get infos on cache and remove it.
1> FileCache -mYY To modify size of cache. (YY en KBytes)
1> FileCache -f Flush cache, all memory used by the files is freed.
1> FileCache -i Give number of file in cache, size of cache, memory
really used by the cache and number of locks on cache.
1> FileCache -q Remove the server and free memory. If you want to use
it again you install it again.
Once installed you can send request to the server.
GENERAL OPERATIONS
------------------
- If you want to use the server you must check if installed by looking at
its public port with FindPort():
struct MsgPort *FileCachePort;
if (FileCachePort = FindPort(FILECACHEPORTNAME))
{
/* serveur is installed */
....
}
else
{
/* No port so the server is not installed */
puts("FileCache Server not installed.");
exit(0);
}
- You must create a port for replies and init the request:
ReplyPort = CreatePort(NULL, 0L);
msg.fcm_Msg.mn_Node.ln_Type = NT_MESSAGE;
msg.fcm_Msg.mn_Length = sizeof(struct FileCacheMsg);
msg.fcm_Msg.mn_ReplyPort = ReplyPort;
- You send request by sending message on the server port:
PutMsg(FileCachePort, &msg);
- You wait for reply:
WaitPort(ReplyPort);
GetMsg(ReplyPort);
- Now you can check the value returned by the server for ex: fcm_Error.
printf("Error code returned = %ld.\n", msg.fcm_Error);
STRUCT FileCacheMsg
-------------------
Requests are sent using a message defined by a struct FileCacheMsg.
struct FileCacheMsg
{
struct Message fcm_Msg;
ULONG fcm_Command;
ULONG fcm_Flags;
ULONG fcm_Error;
union
{
struct
{
STRPTR FileName;
STRPTR *Directory;
ULONG DirIndex;
ULONG FileBuffer;
ULONG FileLength;
ULONG Reserved0;
} FileCmd;
struct
{
ULONG CacheSize;
ULONG MemoryUsed;
UWORD NbFiles;
UWORD NbLocks;
} CacheCmd;
} ExtCmdInfo;
ULONG fcm_Reserved[2];
};
fcm_Msg: It is a standard Exec Message. You must init it before sending
request.
fcm_Command: the command to send (see below).
fcm_Flags: Flags for commands.
fcm_Error: Error code returned by the server, if no error it contains
FC_ERR_OK else FC_ERR_xxx.
The remaining of the struct is defined by the kind of command.
FILECACHE COMMANDS
------------------
There is three kind of command for the server.
- generals commands.
- commands regarding the cache.
- commands regarding the file.
GENERALS COMMANDS
-----------------
Server owns a counter that indiquate the number of locks on the server. If the
counter is zero, there is no lock and the server can be removed.
FC_CMD_GETTOKEN: It is the first request to send to server, it increment lock
counter, so with this command the server can't be removed.
(When exiting your program you must unlock it).
FC_CMD_DELTOKEN: Decrements the lock counter, you must send this request before
exiting your program.
FC_CMD_QUIT: With this command you can remove the server only if lock
counter is zero. at return if fcm_Error is FC_ERR_OK the server
has been removed else it is FC_ERR_INUSE. (Of course you must
send this request after FC_CMD_DELTOKEN).
FC_CMD_FLUSH: This command flush the cache, all files are removed from the
cache, but the server isn't removed.
CACHE COMMANDS
--------------
These commands let you change size of cache, get informations on cache.
FC_CMD_SETMEM: Change the size of cache, the size in bytes you want should
be put in fcm_CacheSize.
FC_CMD_INFO: Give informations on cache. At return check the following
fields:
- fcm_CacheSize size of cache in bytes.
- fcm_MemoryUsed memory really use by cache in bytes.
- fcm_NbFiles number of files in cache.
- fcm_NbLocks number of locks on cache.
FILE COMMANDS
-------------
With these commands you can load file and delete file from cache.
fcm_FileName contains the name of the file to use, with FG_MULTIPLEDIR flag,
the server will look for each filename resulting of the concatenation of
each directory and fcm_FileName, the server will stop at the first filename
for which a file exist. The array of directory MUST end with NULL.
for ex: with FG_MULTIPLEDIR flag
msg.fcm_FileName = "exec/types.h";
/* you must puts NULL at the end of array */
msg.fcm_Directory = { "T:", "", "INCLUDE:", NULL };
msg.fcm_Flags = FG_MULTIPLEDIR;
The server will look for "exec/types.h", "T:exec/types.h" and
"INCLUDE:exec/types.h".
for ex: without FG_MULTIPLEDIR flag
msg.fcm_FileName = "INCLUDE:Amiga/exec/types.h";
msg.fcm_Directory = NULL;
msg.fcm_Flags = 0;
The server will look only for "INCLUDE:Amiga/exec/types.h".
The name of directory must be complete, so you MUST put a '/' or ':' at the
end of each directory in fcm_Directory.
for ex:
"INCLUDE:Amiga" is not a correct directory, you should use instead the
string "INCLUDE:Amiga/".
At the return of request, if no error the field fcm_DirIndex will contain
the directory used.
for ex:
If the fcm_Directory is { "T:", "INCLUDE:Amiga/", "INCLUDE:", NULL }
and at return fcm_DirIndex contains 1 then directory used was
"INCLUDE:Amiga/".
FC_CMD_LOAD:
This command will load a file from the cache, if it is not in cache it
will load it from disk else if it is already in cache the server will
verify by default if the file has been modifed (using creation date), if
the file was modified it will be reloaded in cache else nothing to do.
If yous set the flags FC_NOUPDATE the server don't verify if the file has
been changed, this can be a problem, so i sugger you to use instead the
flag FC_USEWRITEFLAG, with this flag the server will only check files not
protected against writing. You can protect a lot of file against writing
(all Amiga includes). the flag FC_USEWRITEFLAG will speed up compilation.
At return of request if fcm_Error is FC_ERR_OK, you will find in fields
fcm_FileBuffer the address of the block use by the file, fcm_FileLength
contains the size of the file. Each file is load in a single block of
memory and the byte following the end of file is reserved for the user
so you can put a end mark just after the end of file to help to stop
parsing for example.
STRPTR buffer;
buffer = msg.fcm_FileBuffer;
/* put a zero end mark after the end of file */
buffer[msg.fcm_FileLength] = '\0';
FC_CMD_DELETE:
This command will remove a file in cache, you can use FC_MULTIPLEDIR flag.