TempFileMode Property

Summary

Value that indicates whether the temp files are on disk, in memory, or a combination of disk and memory.

Syntax
C#
VB
C++
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) 
   } 

Property 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

Remarks

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:

  • For tiled or disk images.
  • When large blocks of memory are created.
  • When large amounts of data need to be passed to 3rd party toolkits.

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.

Example

This example will use RasterDefaults.TempFileMode to show the effect on creating RasterImage objects with disk (temporary) memory.

C#
VB
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 

Requirements

Target Platforms

Help Version 20.0.2019.9.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2019 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly