←Select platform

TempFileMode Property

Summary

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

Syntax
C#
C++/CLI
Java
Python
public static LeadTempFileMode TempFileMode { get; set; } 
public LeadTempFileMode getTempFileMode(); 
public static void setTempFileMode( 
   LeadTempFileMode leadTempFileMode 
); 
public:  
   static property LeadTempFileMode^ TempFileMode 
   { 
      LeadTempFileMode^ get() 
      void set(LeadTempFileMode^ value) 
   } 
TempFileMode # get and set (RasterDefaults) 

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#
Java
using Leadtools; 
using Leadtools.Codecs; 
 
 
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; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
 
import org.junit.*; 
import org.junit.Test; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
 
 
public void rasterDefaultsTempFileModeExample() { 
   // Store the default value 
   LeadTempFileMode defaultTempFileMode = RasterDefaults.getTempFileMode(); 
   GlobalMemoryThresholds defaultGlobalMemoryThreshold = RasterDefaults.getGlobalMemoryThresholds(); 
 
   // Set to auto 
   System.out.println("RasterDefaults.TempFileMode is Auto"); 
   RasterDefaults.setTempFileMode(LeadTempFileMode.AUTO); 
 
   // Allocating an image should work, normal conventional 
   RasterImage image = RasterImage.create(1024, 1024, 32, 300, RasterColor.fromKnownColor(RasterKnownColor.WHITE)); 
   System.out.println("default options:"); 
   System.out.println("  image.IsConventionalMemory:" + image.isConventionalMemory()); 
   System.out.println("  image.IsDiskMemory:" + image.isDiskMemory()); 
   System.out.println("  image.IsTiled:" + image.isTiled()); 
   assertTrue(image.isConventionalMemory()); 
   assertTrue(!image.isDiskMemory()); 
   assertTrue(!image.isTiled()); 
 
   System.out.println("MaximumConventionalMemory is set to low"); 
   // Change the default maximum memory threshold to something small (1MB) 
   GlobalMemoryThresholds globalMemoryThreshold = RasterDefaults.getGlobalMemoryThresholds(); 
   globalMemoryThreshold.setMaximumConventionalMemory(1 * 1024 * 1024); 
   RasterDefaults.setGlobalMemoryThresholds(globalMemoryThreshold); 
   image.dispose(); 
 
   // Now, the image should be of type disk or tiled 
   RasterImage image2 = RasterImage.create(1024, 1024, 32, 300, RasterColor.fromKnownColor(RasterKnownColor.WHITE)); 
   System.out.println("low global memory threshold:"); 
   System.out.println("  image.IsConventionalMemory:" + image2.isConventionalMemory()); 
   System.out.println("  image.IsDiskMemory:" + image2.isDiskMemory()); 
   System.out.println("  image.IsTiled:" + image2.isTiled()); 
   assertTrue(!image2.isConventionalMemory()); 
   assertTrue(image2.isDiskMemory() || image2.isTiled()); 
 
   // Disable disk for temp files 
   System.out.println("RasterDefaults.TempFileMode is Memory"); 
   RasterDefaults.setTempFileMode(LeadTempFileMode.MEMORY); 
   image2.dispose(); 
 
   // Now it should go back to conventional 
   RasterImage image3 = RasterImage.create(1024, 1024, 32, 300, RasterColor.fromKnownColor(RasterKnownColor.WHITE)); 
   System.out.println("low global memory threshold:"); 
   System.out.println("  image.IsConventionalMemory:" + image3.isConventionalMemory()); 
   System.out.println("  image.IsDiskMemory:" + image3.isDiskMemory()); 
   System.out.println("  image.IsTiled:" + image3.isTiled()); 
   assertTrue(image3.isConventionalMemory()); 
   assertTrue(!image3.isDiskMemory()); 
   assertTrue(!image3.isTiled()); 
 
   // Reset 
   RasterDefaults.setGlobalMemoryThresholds(defaultGlobalMemoryThreshold); 
   RasterDefaults.setTempFileMode(defaultTempFileMode); 
} 
Requirements

Target Platforms

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

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.