PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

High speed file access

Erik Coenders · 11 Jan 2002, 03:55 UTC
Hi,

I am preparing to write an application. Which file access method is the most advisable for the application? It reads continuously some files (100KB to 6MB) from file system at high speed. It is very important to use the physical memory as less as possible. Are memory-mapped files fast enough? Virtual memory?

Thanks in advance,

Erik
memory mapped files aren't any good as they need to be in memory in the first place, what you need is:
1.keep your stuff together, best would be to keep it in one file if possible
2.read as much data as possible with one fread/whatever function. On a PC my test show that on a quite fast hd(7200rpm udma66 ibm) increasing the reading block size by 4 times (so like 64kb instead 16kb) increases the time needed for this operation only by 2. So a huge gain. Also if you're reading from "random" positions in files it's better to read from start to end then to jump all over the file (sort the positions you need to access first and then access them)

This helps you about harddisk access, if you use a flash memory card or so the transfer speed should be much larger and therefore it shouldn't be a problem to load the amount of data you need in well under a second. (if interested in future chat, specify how long it can take for the program to load data and what kind of data you read)

and about how I do it, I use something like this:
FILE *tgafile;
if (!(tgafile = _tfopen(fullname, _T("rb"))))
{
//handle error here
}
//our great fread
fread(&bpp,1,1,tgafile);
...
//close the file
fclose(tgafile);

don't know if it's the best method but I guess it's one of the fastest