Quote:
> What is the most efficient way of writing binary data to disk ?
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
How are you defining "efficient"? By speed or space?
Quote:
> I want to write a set of structures but even after compressing the resultant
> file it takes up too much space.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The fastest method to write lots of structures is to write as large
of a block as possible. Say you had 10 structures to write, then
use:
fwrite(array, sizeof(struct), 10, stream);
Another method is to use Direct Memory Access (DMA) if your platform
has this feature.
Quote:
> The structure to write to file is as follows
> struct
> {
> long
> char[256]
> char[256]
> char[256]
> char[256]
> char[256]
> char[256]
> size_t
> }
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If your looking for compressing the file length, try using variable
length records. This will slow down your program, but you do save
space in the file.
struct var_str_t
{
unsigned int length;
char * string;
Quote:
};
Using this method, write the length of data, followed by the data.
Here are some questions to ask yourself:
1. Is all this data REALLY necessary?
2. Redundancy:
2.1. Is there any redundant data?
2.2. Can the redundant data not be generated?
2.3. Can the redundant data be compressed (stored once)?
3. Can the data be queued, then written as a big chunk 'o data?
--
Thomas Matthews