wlamers
wlamers

Reputation: 1286

Fast binary reading and writing issue regarding 'conflicting' binary formats

I am struggling with the processing of binary (file) data (in c#). This is the situation:

These are the challenges:

I already tried memory mapping of the file to read, but I am stuck with this since I would need to search along the complete file to know the length of the signals.

What would be a good approach to accomplish the above?

Upvotes: 1

Views: 257

Answers (2)

Alois Kraus
Alois Kraus

Reputation: 13545

How about a signal splitter? I would scan once through the file and create a new file for each new signal. During reading the huge file I would write the data to the right signal file. Memory is a non issue since you are always reading only one chunk from disk (about 4KB) which does not get you neary any memory boundary.

If you need some correlation between the signals you would need to insert some timepoint markers into the split files to analyze it time based. That should also be rather easy to do.

As added bonus you do know the signal length by reading its file length or if you do time based stuff I would write a header with the final signal length found during the splitting process.

Upvotes: 0

usr
usr

Reputation: 171216

I would repeatedly scan the entire input file sequentially. Each pass through the file, I would collect as many "signals" in memory as memory can hold. Once the working memory buffer is full I would write the collected "signals" into an output Matlab file and start again to collect more signals with the next pass. Once no more new signals were found the algorithm ends.

This algorithm requires multiple passes over the data for big files but at least it is sequential IO which is rather fast.

Upvotes: 1

Related Questions