what is the difference between random acces files and sequential access?
Printable View
what is the difference between random acces files and sequential access?
anyone?
A random access files records are all fixed length, therefore any record can be found without searching all the other records (by simply using a record key), oh and any record can be inserted or deleted without affecting the whole file.
A sequential access file has records with different lengths so the data must be inserted into the file sequentially, and the whole file is changed each time a record is inserted or deleted.
I think he's not talking about special files with "records" or such, just about a flag of CreateFile (FILE_FLAG_RANDOM_ACCESS vs. FILE_FLAG_SEQUENTIAL_SCAN). Right?
It is only about optimizing. Sequential files are optimized for reading them from the front to the end, with no jumps or anything. Random access files are optimized for jumping around in the file (using SetFilePointer, which is the API version of fseek). Random access is mostly used in structured files, like archives. Archives usually start with a header that tells which files are contained and the offset to the file's data. These offsets are used with SetFilePointer to move to the data. Such jumps are faster when you use a random access file.
ya i dunno, i was just talking about the general idea of sequential/random files in C. nothing i said really applies to anything winAPI related.
although all data files can be considered to have records, there doesnt have to be anything special about it.
nearly all data files are structured, but not all are used with records (look at word docs for example)
there is a simple uncompressed file packaging format which would be good for random access. It is structured like this:
1) The header. This hypothetical structures describes the header:
struct header
{
int num_entries;
header_entry entries[];
};
struct header_entry
{
char filename[]; // '\0'-terminated
int offset;
int length;
};
num_entries is the number of files the package contains. entries is a variable-lenth array with length num_entries of the structure header_entry. filename is a null-terminated string that contains the filename of the packaced file. offset is the offset from the package start to the file data. length is the length of the file.
2) data. This is just a concatenation of all packaged files.
Because of this format, random jumping is very likely.
Did you know...Quote:
Originally posted by CornedBee
nearly all data files are structured, but not all are used with records (look at word docs for example)
...Word files are the same structure as PowerPoint, Excel, Binder files :D
thanks. i was more talking about the core concept of it, i'm not using the API at this point.
Composite documents, probably...
Did you know the mdb format sucks? An empty db (no tables, no queries, no nothing) consumes 50 KB. Adding one table without entries pushes that up to 80 KB. A file currently opened in Access needs twice the space as when closed.
Not surprised really. Compacting helps quite a lot though, if you need to send it anywhere.Quote:
Originally posted by CornedBee
Composite documents, probably...
Did you know the mdb format sucks? An empty db (no tables, no queries, no nothing) consumes 50 KB. Adding one table without entries pushes that up to 80 KB. A file currently opened in Access needs twice the space as when closed.
Same with any Office document - if you want to put it on a floppy, for example, use Save As and put it into a new file (but don't edit that file once saved) and it'll be a lot smaller.
Microsoft had a utility in the Platform SDK that let you browse the contents of Office-style documents.