I have a newbie question, I’ve never read files bigger than 4Mb with function like fopen, ReadFile(WINAPI). My question is What is the best way to read a big file like 400Mb load blocks of 512 bits into memory?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all – at first instance – you may not want to read that small – a few kBytes is better when it comes from disk. In your case – a simple implementation could read 16k – and then cycle through those 32 times for your 512 bytes operations.
In reality that is not so important -as the OS is clever and generally will second guess you – and read more anyway. So a naive implementation where you simply do a
sort of thing is fine.
If you know you are always going to have such (rather large) files, performance is important and there is other use of those files too – then consider ‘memory mapping’ the file – i.e. open it in such a way that the entire file appears in virtual memory. Have a look at http://msdn.microsoft.com/en-us/library/windows/desktop/aa366556(v=vs.85).aspx for that.