1

Topic: How to save a line in binary files?

There is a dial-up of the big text files which operations for acceleration I convert in a convenient format:  separate lines, I lay down the transformed values in fields in structures, structures I lay down in an array, and an array I write down in a binary file smile
How to be with text boxes:
1. If in structure to declare a type field char [250] it will be very prodigal (not to all values such length) is necessary.
2. If in structure to declare a field std:: string the structure ceases to be POD - object and to work with it as with bit sequence it will be already impossible. Possibility of saving of the data in a file As consequence falls off.
There are savings of the text data any the nice decision in binary files?

2

Re: How to save a line in binary files?

"Nice" it is which it is possible to apply not  a brain?.
STFW "serialization in a file".

3

Re: How to save a line in binary files?

Dimitry Sibiryakov wrote:

STFW "serialization in a file".

Thanks, already I read.

4

Re: How to save a line in binary files?

Acceleration and convenience is normal are two mutually exclusive properties.

5

Re: How to save a line in binary files?

6

Re: How to save a line in binary files?

7

Re: How to save a line in binary files?

Serialization has enormous minuses:
1. It is necessary to write/read all structures of the different size, therefore each structure in/from a bin-file separately. I.e. it is impossible to write down/consider at once 10 000 structures from a file.
2. Structure it is impossible to write/read in/from a bin-file as uniform object. It is necessary to work with each field separately.
In other words, such method not :

cchar* pChar = (char *) ArrayOfStructure.begin ();
std:: streamsize MemorySize = ArrayOfStructure. Size () * sizeof (TypeStructure);
File.write (pChar, MemorySize);

Therefore it is lost speed of reading a bin-file for the sake of which all was started.
There is other sentence: the amount of values of the text data is restricted, therefore it is possible to create a separate file with "Index" of used values of lines, and in structures to store only index number. What container to select, that fast search as on a key (was carried out at bin-file reading), and on value (at record bin - a file)?
I can something misunderstood and there is more simple decision?

8

Re: How to save a line in binary files?

AlekseySQL wrote:

Structure it is impossible to write/read in/from a bin-file as uniform object. It is necessary to work with each field separately.

There are 2 variants:
1. To work with variable length fields saving before a field its length (for example), or in file title. This variant "long", but approaches for lines of any length and saves a place;
2. To work with lines (fields) of the identical length in advance known. It is a fast and most convenient variant, except for redundancy.
What to select from a specific case the programmer solves. The variant "that also is not present a line of different length and that all was read at once".

9

Re: How to save a line in binary files?

For choice the container: I think it is necessary to use DIFFERENT map at record and reading bin - a file. In the first case the text line will be a key, and value - an index (so it will be possible to find easily value already added in an index to avoid duplication). At file record all on the contrary: the index (specified in the saved structure) will be a key, and the text line will be value.

10

Re: How to save a line in binary files?

I on the sly from text files create a DB... Can dig is better in this side?

11

Re: How to save a line in binary files?

AlekseySQL;
Probably, for your task quite approaches SQL))
Perhaps it is not necessary ?

12

Re: How to save a line in binary files?

AlekseySQL wrote:

I on the sly from text files create a DB... Can dig is better in this side?

I was not in time)

13

Re: How to save a line in binary files?

AlekseySQL wrote:

For choice the container: I think it is necessary to use DIFFERENT map at record and reading bin - a file. In the first case the text line will be a key, and value - an index (so it will be possible to find easily value already added in an index to avoid duplication). At file record all on the contrary: the index (specified in the saved structure) will be a key, and the text line will be value.

UPDATE:
For choice the container: I think it is necessary to use DIFFERENT map at record and reading bin - a file. In the first case the text line will be a key, and value - an index (so it will be possible to find easily value already added in an index to avoid duplication). At reading a file all on the contrary: the index (specified in the saved structure) will be a key, and the text line will be value.

14

Re: How to save a line in binary files?

AlekseySQL wrote:

Can dig is better in this side?

Dig aside "and  I generally do it?"
Depending on the answer to this question of a direction of digging will be different. From passage on
Stream algorithms of information handling before index creation in storage. Convertings
Text files in binary in between almost for certain will not be, for the sense from it has not enough.

15

Re: How to save a line in binary files?

AlekseySQL wrote:

1. It is necessary to write/read all structures of the different size, therefore each structure in/from a bin-file separately. I.e. it is impossible to write down/consider at once 10 000 structures from a file.

It is possible
[quote =] There is other sentence: the amount of values of the text data is restricted, therefore it is possible to create a separate file with "Index" of used values of lines, and in structures to store only index number. What container to select, that fast search as on a key (was carried out at bin-file reading), and on value (at record bin - a file)?
I can something misunderstood and there is more simple decision?

Development of such idea returns you in far 80 and 90 when "databases on files"
Were popular. It dBase, Paradox, e.t.c. It seems even long lines in them and were stored.
Short -  as fixed size fields.
Actually, the citation which you resulted about that that  - the enemy, demands arguing.
If the enemy - that in what? In complexity of development? In an overhead projector?
Your ideas concerning optimization of saving of the binary data in files () as I already
Wrote - became outdated for 30 years and you should enter the first in opposition with "old men"
Which already "floated" in these technologies and "know" that how much. And to beginners . Will be
For for them it is not visible any profit except development process complication.