.NET arrays

A .NET array (DNA) consists of a header and a block of memory to hold the elements of the array. The header contains information about the array such as the rank and bounds for each dimension. This means that it is not possible to pass part of a DNA to another routine and treat this as another array because the head would be missing or invalid.

Fortran constructions such as EQUIVALENCEs that involve arrays can not be implemented using DNAs. Furthermore, DNAs are considerably less efficient to access than normal Fortran arrays, partly because the array bounds are always checked. For this reason, despite the advent of .NET, no fundamental change has been made in FTN95 with respect to the way in which Fortran arrays are implemented. They are implemented using portions of non-garbage collected memory just as on a Win32 platform.

FTN95 prevents you from declaring arrays whose elements are .NET objects because such objects would not be found by the garbage collector. However, it is possible to manipulate .NET arrays directly. They are objects in their own right and can be declared using the OBJECT keyword. For example:

OBJECT("System.String[]") STR1
OBJECT("System.String[,]") STR2

The variable STR1 is a one-dimensional DNA of strings, whilst STR2 is a corresponding two-dimensional DNA. Like all other objects, you must use NEW@ to allocate memory for a DNA before using it:

STR1=NEW@("System.String[]",10)
STR2=NEW@("System.String[]",10,20)

After executing these two lines of code, STR1 refers to a DNA with one index that is in the range 0:9 (note carefully the zero lower bound) and STR2 refers to a DNA with two indexes in the range (0:9,0:19). It is now possible to access these arrays using subscript syntax:

STR1(k)=mystr
STR2(k,m)="FRED"//STR1(j)

mystr is either a Fortran character string or a DNA. Objects stored in such arrays will be safe if a garbage collection is required.

You cannot use the Fortran substring syntax with a DNA. Also when you pass an element of a DNA to a routine, you will not have implicit access to subsequent elements as is sometimes the case with normal Fortran arrays.

It is important to note that DNAs can be created externally in which case NEW@ will not be used to create the array. For example, a DNA could be a member of a class. In which case the array will be created externally when NEW@ is used for an object of this containing class. Alternatively you might receive a .NET object as an argument in a routine and this object might contain an existing DNA.

See Object and string arrays for an easier, though less fexible way to access .NET arrays.

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited