0

I am using MapVirtualFile to quickly access data from a file. However, this is too slow. I guess it is because the file is huge (300 mb), and I need to read from different locations (for example from the start of the file, then from the end of the file).

I would like to know if somebody has any experience with creating multiple maps from a file. Would that perhaps speed everything up?

I would then for example create 4 maps. One map that point to section 1 in the file, the second map would point to section 2 in the file, the third to section 3 of the file, etc.

Is that possible and would it make reading data faster?

My code is huge, and I would prefer thoughts about this before I invest 2 days just to find out that it does not solve my problem.

Thank you.

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 300Mb is not huge - I would create a memory mapped file over it and use `MapViewOfFile` over the whole lot and just access it as an array. I've used a "windowing" technique on much larger files (~1.5Gb) where I map a 32Mb window during writing and re-map when necessary. – Roger Rowland Sep 14 '13 at 14:49
  • Can you please tell me what you mean by "access it as an array"? How do you get your data "over"? Using MemCopy? – tmighty Sep 14 '13 at 14:52
  • Use `CreateFileMapping` and `MapViewOfFile` to give you a pointer to the start of the data. Then, depending on what format it is, you access it as if it's all in memory. No need to `memcpy` unless you want a copy, you can just read/write to it using pointers. – Roger Rowland Sep 14 '13 at 14:54
  • 1
    What on Earth is "MapVirtualFile"? File data needs to come off a disk, no software is going to make a disk spin faster. Memory mapped files are only beneficial when you need repeated random access to the file data. Mapping more than one view makes no difference. – Hans Passant Sep 14 '13 at 14:54
  • @RogerRowland Ah, thank you. I have always been using MemCopy. How would you do this instead without using MemCpy? unsigned long int iByteStart; memcpy(&iByteStart, &((char*)(m_pVoiceData))[iBytePos],4); – tmighty Sep 14 '13 at 15:01
  • m_pVoiceData is the mapped file. – tmighty Sep 14 '13 at 15:02
  • Or in other words: How do you access data of the mapped file without using MemCpy? – tmighty Sep 14 '13 at 15:10

0 Answers0