Efficient way to write same data to two files [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Just wondering, what would be the most efficient way to write same data to two files, on linux and C/C++.
For example, this is the most trivial way.
while(1) {
... getting data from somewhere ....
write(fd1, data, datalen);
write(fd2, data, datalen);
}
However, the disadvantage is that kernel needs to copy data twice even though the data is same.
Any thoughts?

what would be the most efficient way to write same data to two files
Write the data to one file only.
Copy that file to another. Use an OS call to do that efficiently (Copy a file in a sane, safe and efficient way).
Another way for step 2 would be to create a hard link (check link()).
However, please watch out of not becomning a victim of premature optimization. I this is not the bottleneck in your program, then just use the trivial, easy-it-read approach.

Related

Data compression methods [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Why are most data compression algorithms created with C++ or Java. Why not use javascript or even ruby? Is it dependent on the file type you are trying to compress such as text,video or even audio files?
If you need to compress data, it is probably because you have a lot of data; as such, the performance of such algorithms is pretty important, and other things being equal, a compiled language typically performs better on the kind of low-level data manipulation such algorithms employ than an interpreted one.

C++ multiple big files in one binary file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What is an efficient way to store multiple big files (100Mo to 5Go) in one binary file in c++ ?
For example, if I have an audio file, a very large image file, and a text file, I want to create a binary file that contains these three files and be able to retrieve them latter (to recreate the three original files).
Thanks for your help.
Short answer: Yes.
The long answer is it depends on how you want to package these things, what framing you want to use.
Do you need compression? Do you need random access? One way that's easy to implement is just using the zip container, it's well defined and there's a lot of libraries for creating and manipulating them. The same goes for the tar or cpio format.
The alternative is to write your own container format. This is a lot more difficult, you'll have to write an archiver and extractor.

Is it efficient to have 85620 object of a class? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing a program which reads from a file and processes the data in the file. Each line in the file is an entity. There are 85620 lines in the file. Is it efficient to define a class of the entity and have 85620 instances of that class?
Depends a bit on the class. But in general, 80k objects is a non-concern.
Yes, especially if you're storing them in a memory-efficient container like std::vector (hint: reserve some space up front if you know you always need at least a thousand or so).
It depends on a lot of factor, and the target software/hardware requirements.
On modern computer with 8GB+ memory, 80k object with even 1K each would not be a big deal, however it may be an issue on mobile phone or embedded systems.
Also note that if you are doing single pass processing and do not need the data afterward, there is no reason to store them.

how to minimal WAN data transfer delay time? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have some idea about file remote location.Can i split a file in to chunks and use thread control split and socket to implement split data and send meanwhile ?
Besides, local can prefetch remote chunk and read it by two thread?
If you have one source of data and one sink I would assume that chunking won't help.
The IP-stack itself uses this method, so as long as you can provide data fast enough to the TCP stack (write buffer) and are fast enough reading the data from the buffer (read buffer) I think that is as fast as it gets...

structure reading C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have the following problem:
I have a configuration file that consists a description of fields , which I read it and then parse it. I want to move it into the code to compile it inside.
How would you do that as bug structure ??? or else ?
Thanks
I wouldn't move it into the code, I'd leave the configuration file as a configuration file.
If you really must do this, you can just embed the file as a string resource into the application and use that - that way you'd change only a minimal amount of existing code. The way you do this depends upon your platform.
If thats not feasible (for whatever reason) I'd set up a single configuration class / namespace to contain all the values.
It's not very clear what are you exactly asking.
If you are looking for on-the-fly code execution (like eval() function in some languages), then there is no such thing in C++. It's not an interpreted language which can be read and executed line-by-line, it needs to be compiled every time code changes. While it technically is possible to write self-changing code, it's probably not worth the effort.