G
Giff
Hi all,
I am filling up a class by reading a binary file.
I have a Read(std::string& name) method that opens the file and reads
the inside.
The first few lines of the file contain some text describing the size of
the data that follows; imagine that the file contains some images and
this first line tells the size of the images and their number.
Having this info, what I do is to call a function Init() that allocates
all the necessary memory to be filled up with the raw data coming from
the file. In this way, being always inside the method Read(), I start to
read the actual values only after that the function Init() has returned.
The stream remains open during the call to Init(). I was now thinking:
what if for some reason, when the function returns, the stream has been
closed and the loading of the values fails miserably?
How would you suggest to tackle this problem in a safer way? One way
would be to have two different files: the first with the info about the
data contained in the second one. I am sure there is a better way though.
Thanks.
I am filling up a class by reading a binary file.
I have a Read(std::string& name) method that opens the file and reads
the inside.
The first few lines of the file contain some text describing the size of
the data that follows; imagine that the file contains some images and
this first line tells the size of the images and their number.
Having this info, what I do is to call a function Init() that allocates
all the necessary memory to be filled up with the raw data coming from
the file. In this way, being always inside the method Read(), I start to
read the actual values only after that the function Init() has returned.
The stream remains open during the call to Init(). I was now thinking:
what if for some reason, when the function returns, the stream has been
closed and the loading of the values fails miserably?
How would you suggest to tackle this problem in a safer way? One way
would be to have two different files: the first with the info about the
data contained in the second one. I am sure there is a better way though.
Thanks.