Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory Mapped Files

Status
Not open for further replies.

comaboy

Programmer
Nov 6, 2001
261
GB
Hi all,

I'm trying to understand MMF's - My idea is a batch process that builds a file in memory and then flushes the lot to disk on completion.

Now I'm new to MMF's so I'm probably missing something (like THE POINT! :))

Could someone try to explain what I'm doing wrong in the Psuedo below...

[psuedo]
sFile = "C:\whatever.txt"
FileHandle = CreateFile(sFile...
Call WriteFile(FileHandle,... 'write a few bytes
Call FlushFileBuffers(FileHandle) 'flush the bytes to disk
MappingHandle = CreateFileMapping(FileHandle, Security, PAGE_READWRITE, 0, 0, sFile & "map")
MappingAddress = MapViewOfFile(MappingHandle,...
Do
ProcessSomething
Call WriteFile(MappingHandle,...'Fails (BytesWrittten=0)
Loop Until Whatever
' Flush the lot at once
FlushViewOfFile MappingHandle, 0
Call FlushFileBuffers(MappingHandle)
Call FlushFileBuffers(FileHandle)
[/psuedo]

TIA !
 
Cowboy

CreateFileMapping() sFile & "map" because sFile contains "\". You need to put a name in here that does not contain "\". Such as, "WhateverMap
 
Thanks for tip, Hyper. I'm currently working on another project, but when I get back to this, I'll let you know how I get on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top