Knowledge Base



KB10327 - Explanation of In-Memory and On-Disk vector layers.

To manipulate an object, you first must access it from a layer. With the TatukGIS DK, a vector layer can be either in-memory or on-disk.

  • In-Memory layer
    This means that the whole layer (all shapes) is kept in the RAM. In this situation, every shape has its own private address which is persistent during the session.
  • On-Disk layer
    This means that the whole layer (all shapes) is kept on the disk. In this situation, the shapes are active only for a while. The shape is active only within the scope of a single procedure. The benefit of storing layers on-disk in this manor is quite simple. Every read from disk operation will read into the memory only a single shape. Thanks to this, the DK can efficiently handle very, very large files. (This is a key advantage of the DK over other GIS toolkit products.)

With some vector layer file types (DXF, MIF, TIGER), the DK always loads the layers into memory because random access to the shapes on disk in these formats is not possible. But several other vector layer formats (SHP, DGN TAB, SQL) allow random access to the shapes which always reside on disk. With these file types, selected shapes from the layer exist in-memory only if marked using the MakeEditable method (explained more below).

What does this mean to the DK developer? It means that, unless you are 100% sure that a layer is in-memory, never make any assumptions about the shape pointer, parameters, etc.

For example, do not expect code such as the following to work properly:
 shp.Params.Area.Color := clRed

This command can work for a while – until the next shape is fetched from a disk file to in-memory status. When this happens, changes to the prior shape are lost from memory.

To address this issue, the DK provides the MakeEditable method to maintain hybrid layers. A hybrid layer is a layer which is part disk based, but in which selected shapes are kept in-memory. This provides a perfect solution for editing because only the edited shapes are kept in memory and are joined with the disk based file upon save.

To move your shape into the memory, just call
 myshp := shp.MakeEditable

It is very important to use a newly assigned myshp variable for any subsequent calls. Calling
 shp.MakeEditable
informs the software that the shape is in-memory, but still keeps the old pointer referenced to the disk based file.

Calling MakeEditable is safe. It can be called as many times as wanted without side effects. We recommend that you use it before any “editing” function. For Example:

 shp := layer.GetShape(12) ;
 If Assigned( shp ) then begin
   shp := shp.MakeEditable ; // be sure that it is editable object
   shp.Params.Area.Color := clRed
 end 

An object may be reverted to disk-based status by simply calling layer.Revert( shp.Uid ). This will delete a shape from the in-memory list. But keep in mind that, if used on an in-memory based layer or for a newly created object, the whole shape can be lost.

Comments:

  • Every object created by layer.CreateShape is in-memory.
  • To check if an object is in-memory, call the shp.IsEditable function. But do not do this unless it is really important because the result is obtained by searching the in-memory list, which can slow down the computation.
Created: September 14, 2005, Modified: August 02, 2013
follow us on Facebook  follow us on Twitter  follow us on Google +  follow us on LinkedIn  Embarcadero