By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,374 Members | 2,993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,374 IT Pros & Developers. It's quick & easy.

What is the fastest way to do Data File I/O in C++

P: n/a
Hi everyone,

I am currently using Visual C++ 8 Standard.

I have a quite large data array (1GB) in the form of an unsigned char
array.
I need to save this to disk in 16-bit format (two chars form a 16-bit
value) or 32-bit format (half of 32 bit value empty).

I was wondering what class I should use to save this data as fast as
possible.
Saving it as bytes is not best, as unfortunately the reading program
(Matlab) will have to convert this to 16-bit, and this will take quite
long.

What matters is for this data to end up on disk as fast as possible in
16-bit or 32-bit format.

Any help would be greatly appreciated!

Thank you,
Best regards,
Tele

Aug 7 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Aug 7, 6:48 am, elet.mir...@gmail.com wrote:
Hi everyone,

I am currently using Visual C++ 8 Standard.

I have a quite large data array (1GB) in the form of an unsigned char
array.
I need to save this to disk in 16-bit format (two chars form a 16-bit
value) or 32-bit format (half of 32 bit value empty).

I was wondering what class I should use to save this data as fast as
possible.
Saving it as bytes is not best, as unfortunately the reading program
(Matlab) will have to convert this to 16-bit, and this will take quite
long.

What matters is for this data to end up on disk as fast as possible in
16-bit or 32-bit format.

Any help would be greatly appreciated!

Thank you,
Best regards,
Tele
Use ofstream class.

Aug 7 '07 #2

P: n/a
On Aug 6, 7:55 pm, HumbleWorker <amardeep.develo...@gmail.comwrote:
On Aug 7, 6:48 am, elet.mir...@gmail.com wrote:
Hi everyone,
I am currently using Visual C++ 8 Standard.
I have a quite large data array (1GB) in the form of an unsigned char
array.
I need to save this to disk in 16-bit format (two chars form a 16-bit
value) or 32-bit format (half of 32 bit value empty).
I was wondering what class I should use to save this data as fast as
possible.
Saving it as bytes is not best, as unfortunately the reading program
(Matlab) will have to convert this to 16-bit, and this will take quite
long.
What matters is for this data to end up on disk as fast as possible in
16-bit or 32-bit format.
Any help would be greatly appreciated!
Thank you,
Best regards,
Tele

Use ofstream class.
Any particular reason why I should use ofstream?
As opposed for example to binarywriter or other.

Regards,
Tele

Aug 7 '07 #3

P: n/a
HumbleWorker wrote:
On Aug 7, 6:48 am, elet.mir...@gmail.com wrote:
>Hi everyone,

I am currently using Visual C++ 8 Standard.

I have a quite large data array (1GB) in the form of an unsigned char
array.
I need to save this to disk in 16-bit format (two chars form a 16-bit
value) or 32-bit format (half of 32 bit value empty).

I was wondering what class I should use to save this data as fast as
possible.
Saving it as bytes is not best, as unfortunately the reading program
(Matlab) will have to convert this to 16-bit, and this will take quite
long.

What matters is for this data to end up on disk as fast as possible in
16-bit or 32-bit format.

Any help would be greatly appreciated!

Use ofstream class.
That's probably bad advice!

The good advice is to ask on a windows group for the appropriate
platform specific API.

--
Ian Collins.
Aug 7 '07 #4

P: n/a
On Aug 7, 8:14 am, elet.mir...@gmail.com wrote:
On Aug 6, 7:55 pm, HumbleWorker <amardeep.develo...@gmail.comwrote:


On Aug 7, 6:48 am, elet.mir...@gmail.com wrote:
Hi everyone,
I am currently using Visual C++ 8 Standard.
I have a quite large data array (1GB) in the form of an unsigned char
array.
I need to save this to disk in 16-bit format (two chars form a 16-bit
value) or 32-bit format (half of 32 bit value empty).
I was wondering what class I should use to save this data as fast as
possible.
Saving it as bytes is not best, as unfortunately the reading program
(Matlab) will have to convert this to 16-bit, and this will take quite
long.
What matters is for this data to end up on disk as fast as possible in
16-bit or 32-bit format.
Any help would be greatly appreciated!
Thank you,
Best regards,
Tele
Use ofstream class.

Any particular reason why I should use ofstream?
As opposed for example to binarywriter or other.

Regards,
Tele- Hide quoted text -

- Show quoted text -
BinaryWriters are .NET classes, and they are wrappers around the
streams only. They may not be specifically wrapping around Standard C+
+ streams, but they definitely wrap around something conceptually
similar. If you set the constant ios::binary in the constructor for
fstream, you get a binary writer.

if you can send me your code i can revert back with a complete code.

Thanks.
HW

Aug 7 '07 #5

P: n/a
On Aug 6, 8:58 pm, HumbleWorker <amardeep.develo...@gmail.comwrote:
On Aug 7, 8:14 am, elet.mir...@gmail.com wrote:
On Aug 6, 7:55 pm, HumbleWorker <amardeep.develo...@gmail.comwrote:
On Aug 7, 6:48 am, elet.mir...@gmail.com wrote:
Hi everyone,
I am currently using Visual C++ 8 Standard.
I have a quite large data array (1GB) in the form of an unsigned char
array.
I need to save this to disk in 16-bit format (two chars form a 16-bit
value) or 32-bit format (half of 32 bit value empty).
I was wondering what class I should use to save this data as fast as
possible.
Saving it as bytes is not best, as unfortunately the reading program
(Matlab) will have to convert this to 16-bit, and this will take quite
long.
What matters is for this data to end up on disk as fast as possible in
16-bit or 32-bit format.
Any help would be greatly appreciated!
Thank you,
Best regards,
Tele
Use ofstream class.
Any particular reason why I should use ofstream?
As opposed for example to binarywriter or other.
Regards,
Tele- Hide quoted text -
- Show quoted text -

BinaryWriters are .NET classes, and they are wrappers around the
streams only. They may not be specifically wrapping around Standard C+
+ streams, but they definitely wrap around something conceptually
similar. If you set the constant ios::binary in the constructor for
fstream, you get a binary writer.

if you can send me your code i can revert back with a complete code.

Thanks.
HW
Thanks, this information helps.
I didn't know BinaryWriters wrapped around streams, but I know how to
use ios::binary.
Thanks!
Tele

Aug 7 '07 #6

P: n/a
I am currently using Visual C++ 8 Standard.

fstream are quite slow on Visual Studio's implementation. I found
fopen/fwrite to be pretty fast, but the API might be an even better
choice.
comp.os.ms-windows.programmer.win32 might be a place to ask.
Aug 7 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.