Value that indicates whether the temp files are on disk, in memory, or a combination of disk and memory.
public static LeadTempFileMode TempFileMode { get; set; }
Public Shared Property TempFileMode() As LeadTempFileMode
Get
Set
public:
static property LeadTempFileMode^ TempFileMode
{
LeadTempFileMode^ get()
void set(LeadTempFileMode^ value)
}
Value that indicates whether the temp files are on disk, in memory, or a combination of disk and memory. The default value is TempFileMode.Auto
This value can be used to get/set the temp file options. These options are global (all threads use the same settings).
Possible values are:
Value | Description |
---|---|
Auto | Lets LEADTOOLS pick the default mode (behavior might change from one version to another). Currently, it is the same as DiskAndMemory . |
Disk | Disk only, do not use memory to back up temp files. |
DiskAndMemory | Uses memory for small temp files, disk for large temp files. |
Memory | Disables disk: all temp files should be created in memory. Some features might fail with if they require temporary files on disk. The failure might be an out-of-memory error or a RasterException with code set to RasterExceptionCode.TempFileDiskDisabled. |
LEADTOOLS sometimes needs to use temporary files for certain operations. Temp files are used under the following conditions:
The fine control over temp files is available in version 20 or higher. In version 19 or earlier, all temp files were kept on disk.
By default, LEADTOOLS keeps small temporary files in memory and large temporary files on disk. But you can also specify that all the temporary files should be kept on disk (LeadTempFileMode.Disk) or that all temporary files should be kept in memory (LeadTempFileMode.Memory).
The most common reason for using memory-only temp file mode is in cloud applications. In some cloud environments, disk access is more expensive than memory. In such situations, a memory-only temporary file mode might make sense.
If you set RasterDefaults.TempFileMode to LeadTempFileMode.Disk, you will be unable to create disk images and the tiles in a tiled image will be in memory. In this situation, certain operations will fail with out-of-memory errors or with a RasterException with code set to RasterExceptionCode.TempFileDiskDisabled.
If disk temp files are enabled, they will be stored in the folder set with RasterDefaults.TemporaryDirectory. There are a few exceptions to this rule: LEADTOOLS uses some 3rd party libraries that require files in a certain folder. Also, some 3rd party libraries create temporary files internally and do not offer a way to control their location.
This example will use RasterDefaults.TempFileMode
to show the effect on creating RasterImage
objects with disk (temporary) memory.
using Leadtools;
using Leadtools.Codecs;
using LeadtoolsExamples.Common;
public static void RasterDefaults_TempFileMode_Example()
{
// Store the default value
LeadTempFileMode defaultTempFileMode = RasterDefaults.TempFileMode;
GlobalMemoryThresholds defaultGlobalMemoryThreshold = RasterDefaults.GetGlobalMemoryThresholds();
// Set to auto
Console.WriteLine("RasterDefaults.TempFileMode is Auto");
RasterDefaults.TempFileMode = LeadTempFileMode.Auto;
// Allocating an image should work, normal conventional
using (var image = RasterImage.Create(1024, 1024, 32, 300, RasterColor.FromKnownColor(RasterKnownColor.White)))
{
Console.WriteLine("default options:");
Console.WriteLine(" image.IsConventionalMemory:" + image.IsConventionalMemory);
Console.WriteLine(" image.IsDiskMemory:" + image.IsDiskMemory);
Console.WriteLine(" image.IsTiled:" + image.IsTiled);
Debug.Assert(image.IsConventionalMemory);
Debug.Assert(!image.IsDiskMemory);
Debug.Assert(!image.IsTiled);
}
Console.WriteLine("MaximumConventionalMemory is set to low");
// Change the default maximum memory threshold to something small (1MB)
GlobalMemoryThresholds globalMemoryThreshold = RasterDefaults.GetGlobalMemoryThresholds();
globalMemoryThreshold.MaximumConventionalMemory = 1 * 1024 * 1024;
RasterDefaults.SetGlobalMemoryThresholds(globalMemoryThreshold);
// Now, the image should be of type disk or tiled
using (var image = RasterImage.Create(1024, 1024, 32, 300, RasterColor.FromKnownColor(RasterKnownColor.White)))
{
Console.WriteLine("low global memory threshold:");
Console.WriteLine(" image.IsConventionalMemory:" + image.IsConventionalMemory);
Console.WriteLine(" image.IsDiskMemory:" + image.IsDiskMemory);
Console.WriteLine(" image.IsTiled:" + image.IsTiled);
Debug.Assert(!image.IsConventionalMemory);
Debug.Assert(image.IsDiskMemory || image.IsTiled);
}
// Disable disk for temp files
Console.WriteLine("RasterDefaults.TempFileMode is Memory");
RasterDefaults.TempFileMode = LeadTempFileMode.Memory;
// Now it should go back to conventional
using (var image = RasterImage.Create(1024, 1024, 32, 300, RasterColor.FromKnownColor(RasterKnownColor.White)))
{
Console.WriteLine("low global memory threshold:");
Console.WriteLine(" image.IsConventionalMemory:" + image.IsConventionalMemory);
Console.WriteLine(" image.IsDiskMemory:" + image.IsDiskMemory);
Console.WriteLine(" image.IsTiled:" + image.IsTiled);
Debug.Assert(image.IsConventionalMemory);
Debug.Assert(!image.IsDiskMemory);
Debug.Assert(!image.IsTiled);
}
// Reset
RasterDefaults.SetGlobalMemoryThresholds(defaultGlobalMemoryThreshold);
RasterDefaults.TempFileMode = defaultTempFileMode;
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Controls
Imports Leadtools.Dicom
Imports Leadtools.Drawing
Imports Leadtools.Svg
Public Shared Sub RasterDefaults_TempFileMode_Example()
' Store the default value
Dim defaultTempFileMode As LeadTempFileMode = RasterDefaults.TempFileMode
Dim defaultGlobalMemoryThreshold As GlobalMemoryThresholds = RasterDefaults.GetGlobalMemoryThresholds()
' Set to auto
Console.WriteLine("RasterDefaults.TempFileMode is Auto")
RasterDefaults.TempFileMode = LeadTempFileMode.Auto
' Allocating an image should work, normal conventional
Using image As RasterImage = RasterImage.Create(1024, 1024, 32, 300, RasterColor.FromKnownColor(RasterKnownColor.White))
Console.WriteLine("default options:")
Console.WriteLine(" image.IsConventionalMemory:" + image.IsConventionalMemory.ToString())
Console.WriteLine(" image.IsDiskMemory:" + image.IsDiskMemory.ToString())
Console.WriteLine(" image.IsTiled:" + image.IsTiled.ToString())
Debug.Assert(image.IsConventionalMemory)
Debug.Assert(Not image.IsDiskMemory)
Debug.Assert(Not image.IsTiled)
End Using
Console.WriteLine("MaximumConventionalMemory is set to low")
' Change the default maximum memory threshold to something small (1MB)
Dim globalMemoryThreshold As GlobalMemoryThresholds = RasterDefaults.GetGlobalMemoryThresholds()
globalMemoryThreshold.MaximumConventionalMemory = 1 * 1024 * 1024
RasterDefaults.SetGlobalMemoryThresholds(globalMemoryThreshold)
' Now, the image should be of type disk Or tiled
Using image As RasterImage = RasterImage.Create(1024, 1024, 32, 300, RasterColor.FromKnownColor(RasterKnownColor.White))
Console.WriteLine("low global memory threshold:")
Console.WriteLine(" image.IsConventionalMemory:" + image.IsConventionalMemory.ToString())
Console.WriteLine(" image.IsDiskMemory:" + image.IsDiskMemory.ToString())
Console.WriteLine(" image.IsTiled:" + image.IsTiled.ToString())
Debug.Assert(Not image.IsConventionalMemory)
Debug.Assert(image.IsDiskMemory OrElse image.IsTiled)
End Using
' Disable disk for temp files
Console.WriteLine("RasterDefaults.TempFileMode is Memory")
RasterDefaults.TempFileMode = LeadTempFileMode.Memory
' Now it should go back to conventional
Using image As RasterImage = RasterImage.Create(1024, 1024, 32, 300, RasterColor.FromKnownColor(RasterKnownColor.White))
Console.WriteLine("low global memory threshold:")
Console.WriteLine(" image.IsConventionalMemory:" + image.IsConventionalMemory.ToString())
Console.WriteLine(" image.IsDiskMemory:" + image.IsDiskMemory.ToString())
Console.WriteLine(" image.IsTiled:" + image.IsTiled.ToString())
Debug.Assert(image.IsConventionalMemory)
Debug.Assert(Not image.IsDiskMemory)
Debug.Assert(Not image.IsTiled)
End Using
' Reset
RasterDefaults.SetGlobalMemoryThresholds(defaultGlobalMemoryThreshold)
RasterDefaults.TempFileMode = defaultTempFileMode
End Sub
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document