Quote:Original post by vaneger
*** Source Snippet Removed ***
Thats the finished function. It reads a kilobyte at a time, but can be adjusted via sizeOfRead.
Any suggested improvements ?
Depending on the intended use of this function you may want to:
Change it to accept an istream instead of manually opening the file each time.
Validate that the stream has all the data you are attempting to read: sizeOfRead * sizeof(int) + offset.
Reserve memory in the vector before beggining the looping push_backs. (vector.size() + sizeOfRead). This will avoid multiple reallocations and copies in the vector.
clear the vector before use, unless the intent is to append to the vector.
Consider using iterators, between the file stream and the vector all operations can be done via iterators so that your function doesn't car what type of containers it is working with. You can then use things like std::copy. I do not know if you will still need to do the reserve call or not or if the std::copy effeciently resizes the output iterator's matching class. I, honestly do not use the stl very often.
// Full Sail graduate with a passion for games// This post in no way indicates my being awake when writing it