Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to write data stream to disk

Tags:

c++

I have an image stream coming in from a camera at about 100 frames/second, with each image being about 2 MB. Now just because of the disk write speed I know I can't write each frame, so I'm only trying to save about a third of those frames each second.

The stream is a circular buffer of large char arrays. And right now I'm using fwrite to dump each array to a temporary file as it gets buffered, but it only seems to be writing at about 20-30 MB/s while the hard drive should theoretically go up to 80-100 MB/s

Any thoughts? Is there a faster way to write than fwrite() or a way to optimize it? More generally what is the fastest way to dump large amounts of a data to a standard hard drive?

like image 893
user1359341 Avatar asked Dec 04 '25 06:12

user1359341


1 Answers

What if you'll use memory mapped files limited to, for example, 1GB each? This should provide enough speed and buffer to work with all frames, especially if you'll manage to perform zero-copy frame allocation.

like image 188
Forgottn Avatar answered Dec 05 '25 23:12

Forgottn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!