Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by Giovanni
Tue, 04 Mar 2003 15:03
Memory Mapped File
Author: Giovanni
Date: Tue, 04 Mar 2003 15:03
Date: Tue, 04 Mar 2003 15:03
25 lines
1442 bytes
1442 bytes
Hi all, I have Win NT 4.0 SP 6.0a (ita) I need to read 7-8 avi video files (dimensions around 30-200 Mb each). I use MMF with this code: HANDLE hFileMapping; hFileMapping=CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,NULL); CloseHandle(hFile); lpMapApp = MapViewOfFile(hFileMapping,FILE_MAP_READ,0,0,0); CloseHandle(hFileMapping); I need to switch beetwen them without swapping ( I have 200 Mb ram memory free). Unfortunally my computer is swapping even if I created a mmf for ALL file. Suggestion to avoid swapping? Thanks Gvl
Re: Memory Mapped File
Author: Early Ehlinger
Date: Tue, 04 Mar 2003 15:28
Date: Tue, 04 Mar 2003 15:28
37 lines
2731 bytes
2731 bytes
Three things: 1. I'm pretty sure you need to keep hFile and hFileMapping open, along with unmapping the view when you're done you're done with the info: hFile = CreateFile(...); hFileMapping=CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,NULL); lpMapApp = MapViewOfFile(hFileMapping,FILE_MAP_READ,0,0,0); /* use lpMapApp */ UnmapViewOfFile( lpMapApp ); /* must come before ... */ CloseHandle(hFileMapping); /* must come before ... */ CloseHandle(hFile); /* file is now officially closed */ 2. MMIO does not guarantee that you will not swap. What it does is take a section of your process's virtual address space and set up the virtual-memory system so that that section is "backed" by the file itself. In other words, the first time you access the virtual address stored in lpMapApp, you will cause a page fault which will have the effect of reading at least 1 page of the file into physical memory. You are *not* guaranteed at this point that this physical page of RAM will not get cleared out for another thread/process to use if necessary. You *are* guaranteed that every time you access the virtual address, the information from the file will be available. Will there be a page fault each time you access the address? In all probability, no. But there is no guarantee at this point. 3. If you want to lock pages of RAM into physical memory, the API you're looking for is VirtualLock. -- -- Early Ehlinger CEO, ResPower Inc - Toll-Free : 866-737-7697 -- - RenderFarm - Lightwave , 3dSMax , Bryce , Maya , AfterEffects - --- www.respower.com -- 500+ GHz Starting At USD$0.50/GHz*Hour -- ----------------- SuperComputing For the Masses! ---------------- "I'm so busy programming my computer to let me be lazy, I never get any rest!" - John Kaster
Re: Memory Mapped File
Author: Remy Lebeau (TeamB)
Date: Tue, 04 Mar 2003 18:11
Date: Tue, 04 Mar 2003 18:11
20 lines
1398 bytes
1398 bytes
"Giovanni" <giolaser@libero.it> wrote in message news:3e64c04a$1@newsgroups.borland.com... > hFileMapping=CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,NULL); > > CloseHandle(hFile); You shouldn't close the file until after you're actually finished reading the data from it. > lpMapApp = MapViewOfFile(hFileMapping,FILE_MAP_READ,0,0,0); > > CloseHandle(hFileMapping); You shouldn't close the file mapping until after you're actually finished reading the data from it. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads