Hello everyone,
Im having trouble saving information into a binary file, and i guess thats a problem concerning speed. Mi program recieves from an UDP SOCKET 1280 bytes every 2.5 ms. From those 1280 bytes, i only need to save half of them, 640 bytes. To do this, i save a specific amount into a static variable, and I save them after some time (to avoid opening and closing a file really often).
What im saving is the following struct.
|
MySQL queries
|
1
2
3
4
5
|
struct info
{
unsigned char trama [CANT_PAQ][640];
}
|
Where CANT_PAQ is a define, for example, if I set it into 1000, i will store 1000 arrays of 640 bytes before saving them into my file. The problem is that when the file is created and i loose some information. For example, i wont have any trouble saving the first 999 arrays, bue then, if i recieve 10 more, only 5 will be saved. Apparently creating the file takes some time, and im loosing some packages. The code I use to save the binary file is the following:
|
MySQL queries
|
1
2
3
4
5
6
7
8
|
QString path;
path="Package_";
path=path+path.number(numer_files); /*number_files tells how many files i have already saved, so the first one will be package_1.dat,
and the second one package_2.dat, etc */
path.append(".dat");
ofstream file (path.toascii(),ios::out|ios::binary);
file.write(reinterpret_cast<char*>(&temporal_struct),sizeof(info)); /*Temporal struct is where i have saved the information and its a "info"struct */
file.close();
|
Thats how i save information, but apparenlty its not fast enough. Ive tired varying CANT_PAQ, so i save larger files less often, or smaler files really fast, but im always loosing some information. I would appreciate if someone could tell me if theres a faster way to do this, or a way to give a higher priorty to this part of the program.
Thanks in advance!