Platforms to show: All Mac Windows Linux Cross-Platform

/Util/Filemapping/Huge Temp Storage


Required plugins for this example: MBS Util Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Filemapping/Huge Temp Storage

This example is the version from Sun, 17th Mar 2012.

Project "Huge Temp Storage.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control CreateButton Inherits PushButton
ControlInstance CreateButton Inherits PushButton
EventHandler Sub Action() Create val(SizeInput.text) End EventHandler
End Control
Control SizeInput Inherits TextField
ControlInstance SizeInput Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control DestroyButton Inherits PushButton
ControlInstance DestroyButton Inherits PushButton
EventHandler Sub Action() destroy End EventHandler
End Control
Control FillButton Inherits PushButton
ControlInstance FillButton Inherits PushButton
EventHandler Sub Action() Fill InputText.text End EventHandler
End Control
Control InputText Inherits TextField
ControlInstance InputText Inherits TextField
End Control
Control MySlider Inherits Slider
ControlInstance MySlider Inherits Slider
EventHandler Sub ValueChanged() readat me.Value End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control data Inherits TextArea
ControlInstance data Inherits TextArea
End Control
Sub Create(n as integer) dim Blocksize as int64 = 1048576 dim size as int64 = Blocksize * n if TargetWin32 then filemapping = new FilemappingMBS(nil, true) // create in swap space if not filemapping.OpenFileMapping(size) then // and open with the size we need MsgBox "Failed to create file mapping." Return end if else dim file as FolderItem = GetTemporaryFolderItem // put somewhere on disc filemapping = new FilemappingMBS(file, true) // open with temp file filemapping.DeleteFileOnClose = true filemapping.ShrinkFileOnClose = true filemapping.EnlargeFile(size) // increase file size to the size we need if Filemapping.Lasterror <> 0 then MsgBox "Failed to create file mapping." Return end if end if totalsize = size LastOffset = -1 DestroyButton.Enabled = true CreateButton.Enabled = false FillButton.Enabled = true MySlider.Enabled = true data.text = "" MySlider.Maximum = n-1 dim v as FileMappingViewMBS = FileMapping.MapView(0, 10000) if v<>nil then v.Memory.StringValue(0,5)="Hello" MsgBox v.Memory.StringValue(0,5) v.FlushView v = nil end if readat MySlider.Value End Sub
Sub Fill(s as string) s = ConvertEncoding(s, encodings.UTF8) dim v as FileMappingViewMBS dim Offset as int64 = 0 dim Blocksize as int64 = 1048576 dim m as MemoryBlock while Offset<totalsize if Offset mod blocksize = 0 then if LastOffset <> Offset then m = nil v = nil v = Filemapping.MapView(Offset, blocksize) if v = nil then MsgBox "Failed to map data at offset: "+str(Offset) Return end if m = v.Memory LastOffset = Offset end if end if dim ss as string = str(Offset)+" Bytes: "+s m.StringValue(Offset mod blocksize, lenb(ss)) = ss Offset = Offset + 1024 wend m = nil v = nil readat MySlider.Value End Sub
Sub destroy() Filemapping = nil // destructor does unmap, close file mapping, close, shrink and delete file DestroyButton.Enabled = false CreateButton.Enabled = true FillButton.Enabled = false MySlider.Enabled = False data.text = "" End Sub
Sub readat(value as integer) dim Blocksize as int64 = 1048576 dim offset as int64 = value * Blocksize dim v as FileMappingViewMBS = Filemapping.MapView(offset, Blocksize) if v<>nil then dim s as MemoryBlock = v.Memory.StringValue(0, Blocksize) dim eol as string = EndOfLine for i as integer = 0 to 1024*1024-1 if s.UInt8Value(i)=0 then // replace chr(0) with spaces s.UInt8Value(i)=32 end if if i mod 128 = 127 then // replace a few bytes every x bytes with EndOfLine s.StringValue(i+1-lenb(eol), lenb(eol)) = eol end if next data.text = DefineEncoding(s, Encodings.ASCII) else data.text = "" end if End Sub
Property LastOffset As int64
Property filemapping As FilemappingMBS
Property tempfile As FolderItem
Property totalsize As int64
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

The items on this page are in the following plugins: MBS Util Plugin.


The biggest plugin in space...