- •Important Information
- •Warranty
- •Copyright
- •Trademarks
- •Organization of This Manual
- •Conventions Used in This Manual
- •Related Documentation
- •Customer Communication
- •Classes of External Code
- •Introduction
- •Supported Languages
- •Macintosh
- •Microsoft Windows 3.1
- •Microsoft Windows 95 and Windows NT
- •Solaris
- •Steps for Creating a CIN
- •1. Place the CIN on a Block Diagram
- •2. Add Input and Output Terminals to the CIN
- •Input-Output Terminals
- •Output-Only Terminals
- •3. Wire the Inputs and Outputs to the CIN
- •4. Create .c File
- •Special Macintosh Considerations
- •5. Compile the CIN Source Code
- •Macintosh
- •THINK C for 68K (Versions 5-7)
- •Symantec C++ 8.0 for Power Macintosh
- •Metrowerks CodeWarrior for 68K
- •Metrowerks CodeWarrior for Power Macintosh
- •Microsoft Windows 3.x
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Microsoft SDK C/C++ Compiler
- •Visual C++ for Windows 95 or Windows NT
- •Solaris 1.x
- •Solaris 2.x
- •6. Load the CIN Object Code
- •LabVIEW Manager Routines
- •Online Reference
- •Pointers as Parameters
- •Debugging External Code
- •DbgPrintf
- •Debugging CINs Under Windows 95 and Windows NT
- •Debugging CINs Under Sun or Solaris
- •Debugging CINs Under HP-UX
- •Introduction
- •CIN .c File
- •How LabVIEW Passes Fixed Sized Data to CINs
- •Scalar Numerics
- •Scalar Booleans
- •Refnums
- •Clusters of Scalars
- •Return Value for CIN Routines
- •Examples with Scalars
- •1. Place the CIN on the Block Diagram
- •2. Add Two Input and Output Terminals to the CIN
- •3. Wire the Inputs and Outputs to the CIN
- •4. Create the CIN Source Code
- •5. Compile the CIN Source Code
- •Macintosh
- •THINK C for 68K and Symantec C++
- •Microsoft Windows 3.x
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Microsoft SDK Compiler
- •Microsoft Visual C++ Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •6. Load the CIN Object Code
- •Comparing Two Numbers, Producing a Boolean Scalar
- •How LabVIEW Passes Variably Sized Data to CINs
- •Alignment Considerations
- •Arrays and Strings
- •Paths (Path)
- •Clusters Containing Variably Sized Data
- •Resizing Arrays and Strings
- •SetCINArraySize
- •NumericArrayResize
- •Examples with Variably Sized Data
- •Concatenating Two Strings
- •Working with Clusters
- •CIN Routines
- •Data Spaces and Code Resources
- •CIN Routines: The Basic Case
- •Loading a VI
- •Unloading a VI
- •Loading a New Resource into the CIN
- •Compiling a VI
- •Running a VI
- •Saving a VI
- •Aborting a VI
- •Multiple References to the Same CIN
- •Reentrancy
- •Code Globals and CIN Data Space Globals
- •Examples
- •Using Code Globals
- •Using CIN Data Space Globals
- •Calling a Windows 3.1 Dynamic Link Library
- •2. Get the address of the desired function
- •3. Describe the function
- •4. Call the function
- •Calling a 16-Bit DLL
- •1. Load the DLL
- •Example: A CIN that Displays a Dialog Box
- •The Block Diagram
- •The CIN Code
- •Compiling the CIN
- •Optimization
- •Introduction
- •Creating Shared External Subroutines
- •External Subroutine
- •Macintosh
- •THINK C Compiler and CodeWarrior 68K Compiler
- •MPW Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Calling Code
- •Macintosh
- •THINK C Compiler
- •CodeWarrior 68K Compiler
- •MPW Compiler
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Simple Example
- •External Subroutine Example
- •Compiling the External Subroutine
- •Macintosh
- •THINK C Compiler and CodeWarrior 68K Compiler
- •MPW Compiler
- •Microsoft Windows 3.1
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Calling Code
- •Compiling the Calling Code
- •Macintosh
- •THINK C Compiler
- •CodeWarrior 68K Compiler
- •MPW Compiler
- •Microsoft Windows 3.1
- •Watcom C Compiler
- •Microsoft Windows 95 and Windows NT
- •Solaris 1.x, Solaris 2.x, and HP-UX
- •Introduction
- •Basic Data Types
- •Scalar Data Types
- •Booleans
- •Numerics
- •Complex Numbers
- •char Data Type
- •Dynamic Data Types
- •Arrays
- •Strings
- •C-Style Strings (CStr)
- •Pascal-Style Strings (PStr)
- •LabVIEW Strings (LStr)
- •Concatenated Pascal String (CPStr)
- •Paths (Path)
- •Memory-Related Types
- •Constants
- •Memory Manager
- •Memory Allocation
- •Static Memory Allocation
- •Dynamic Memory Allocation: Pointers and Handles
- •Memory Zones
- •Using Pointers and Handles
- •Simple Example
- •Reference to the Memory Manager
- •Memory Manager Data Structures
- •File Manager
- •Introduction
- •Identifying Files and Directories
- •Path Specifications
- •Conventional Path Specifications
- •Empty Path Specifications
- •LabVIEW Path Specification
- •File Descriptors
- •File Refnums
- •Support Manager
- •Allocating and Releasing Handles
- •Allocating and Releasing Pointers
- •Manipulating Properties of Handles
- •AZHLock
- •AZHPurge
- •AZHNoPurge
- •AZHUnlock
- •Memory Utilities
- •ClearMem
- •MoveBlock
- •SwapBlock
- •Handle and Pointer Verification
- •Memory Zone Utilities
- •File Manager Data Structures
- •File/Directory Information Record
- •File Type Record
- •Path Data Type
- •Permissions
- •Volume Information Record
- •File Manager Functions
- •Performing Basic File Operations
- •FCreate
- •FCreateAlways
- •FMClose
- •FMOpen
- •FMRead
- •FMWrite
- •Positioning the Current Position Mark
- •FMSeek
- •FMTell
- •Positioning the End-Of-File Mark
- •FGetEOF
- •FSetEOF
- •Flushing File Data to Disk
- •FFlush
- •FExists
- •FGetAccessRights
- •FGetInfo
- •FGetVolInfo
- •FSetAccessRights
- •FSetInfo
- •Getting Default Access Rights Information
- •FGetDefGroup
- •FListDir
- •FNewDir
- •Copying Files
- •FCopy
- •Moving and Deleting Files and Directories
- •FMove
- •FRemove
- •Locking a File Range
- •FLockOrUnlockRange
- •Matching Filenames with Patterns
- •FStrFitsPat
- •Creating Paths
- •FAddPath
- •FAppendName
- •FAppPath
- •FEmptyPath
- •FMakePath
- •FNotAPath
- •FRelPath
- •Disposing Paths
- •FDisposePath
- •Duplicating Paths
- •FPathCpy
- •FPathToPath
- •Extracting Information from a Path
- •FDepth
- •FDirName
- •FName
- •FNamePtr
- •FVolName
- •FArrToPath
- •FFlattenPath
- •FPathToArr
- •FPathToAZString
- •FPathToDSString
- •FStringToPath
- •FTextToPath
- •FUnFlattenPath
- •Comparing Paths
- •FIsAPath
- •FIsAPathOrNotAPath
- •FIsEmptyPath
- •FPathCmp
- •Determining a Path Type
- •FGetPathType
- •FIsAPathOfType
- •FSetPathType
- •Manipulating File Refnums
- •FDisposeRefNum
- •FIsARefNum
- •FNewRefNum
- •FRefNumToFD
- •FRefNumToPath
- •Byte Manipulation Operations
- •Mathematical Operations
- •For THINK C Users
- •RandomGen
- •String Manipulation
- •BlockCmp
- •CPStrCmp
- •CPStrIndex
- •CPStrInsert
- •CPStrRemove
- •CPStrReplace
- •CPStrSize
- •CToPStr
- •HexChar
- •IsAlpha
- •IsDigit
- •IsLower
- •IsUpper
- •LStrCmp
- •LToPStr
- •PPStrCaseCmp
- •PPStrCmp
- •PStrCaseCmp
- •PStrCat
- •PStrCmp
- •PStrCpy
- •PStrNCpy
- •PToCStr
- •PToLStr
- •StrCat
- •StrCmp
- •StrCpy
- •StrLen
- •StrNCaseCmp
- •StrNCmp
- •StrNCpy
- •ToLower
- •ToUpper
- •Utility Functions
- •BinSearch
- •QSort
- •Time Functions
- •ASCIITime
- •DateCString
- •DateToSecs
- •MilliSecs
- •SecsToDate
- •TimeCString
- •TimeInSecs
- •Microsoft Windows 3.1, Windows 95, and Windows NT
- •Macintosh
- •How do I debug my CIN?
- •Can LabVIEW be used to call a DLL in Windows?
- •Glossary
- •Index
Chapter 5 Manager Overview
You use handles to perform most memory allocation in LabVIEW. Pointers are available, however, because in some cases they are more convenient and simpler to use.
Memory Zones
LabVIEW's memory manager interface has the ability to distinguish between two distinct sections, called zones. LabVIEW uses the data space (DS) zone only to hold VI execution data. LabVIEW uses the application zone (AZ) to hold all other data. Most memory manager functions have two corresponding routines, one for each of the two zones. Routines that operate on the data space zone begin with DS and routines for the application zone begin with AZ.
Currently, the two zones are actually one zone, but this may change in future releases of LabVIEW; therefore, a CIN programmer should write programs as if the two zones actually exist.
External code modules work almost exclusively with data created in the DS zone, although exceptions exist. In most cases, you use the DS routines when you need to work with dynamically allocated memory.
All data passed to or from a CIN is allocated in the DS zone except for Paths, which use AZ handles. You should only use file manager functions (not the AZ memory manager routines) to manipulate Paths. Thus, your CINs should use the DS memory routines when working with parameters passed from the block diagram. The only exceptions to this rule are handles created using the SizeHandle function, which allocates handles in the application zone. If you pass one of these handles to a CIN, your CIN should use AZ routines to work with the handle.
Using Pointers and Handles
Most memory manager functions have a DS routine and an AZ routine. In the following discussion, XXFunctionName refers to a function in a general context. In these situations, XX can be either DS or AZ. When a difference exists between the two zones, the specific function name is given.
You create a handle using XXNewHandle, with which you specify the size of the memory block. You create a pointer using XXNewPtr. XXNewHandleClr and XXNewPtrClr are variations that create the memory block and set it to all zeros.
© National Instruments Corporation |
5-9 |
LabVIEW Code Interface Reference Manual |
Chapter 5 Manager Overview
When you are finished with the handle or pointer, release it using
XXDisposeHandle or XXDisposePtr.
If you need to resize an existing handle, you can use the
XXSetHandleSize routine. XXGetHandleSize determines the size of an existing handle. Because pointers are not relocatable, you cannot resize them.
A handle is a pointer to a pointer. In other words, a handle is the address of an address. The second pointer, or address, is a master pointer, which means that it is maintained by the memory manager. Languages that support pointers provide operators for accessing data by its address. With a handle, you use this operator twice; once to get to the master pointer, and a second time to get to the actual data. A simple example of how to work with pointers and handles in C is shown in the following section. Examples in the Online Reference show more complex ways to work with handles.
While operating within a single call of a CIN node, an AZ handle will not move unless you specifically resize it. In this context there is no need to lock or unlock handles. If your CIN maintains an AZ handle across different calls of the same CIN (an asynchronous CIN), the AZ handle may be relocated between calls. In this case, AZHLock and AZHUnlock may be useful if you do not want the handle to relocate. A DS handle will never move unless you resize it.
You can explicitly purge a handle using XXEmptyHandle. You can reallocate a purged master pointer using XXReallocHandle. Notice that XXReallocHandle does not actually recover the data to which the handle refers; this routine only reallocates a block of memory for the handle.
Additional routines make it easy to copy and concatenate handles and pointers to other handles, check the validity of handles and pointers, and copy or move blocks of memory from one place to another.
Simple Example
The following example code shows how you work with a pointer to an int32.
int32 *myInt32P;
myInt32P = (int32 *)DSNewPtr(sizeof(int32)); *myInt32P = 5;
LabVIEW Code Interface Reference Manual |
5-10 |
© National Instruments Corporation |
Chapter 5 Manager Overview
x = *myInt32P + 7;
...
DSDisposePtr(myInt32P);
The first line declares the variable myInt32P as a pointer to, or the address of, a signed 32-bit integer. This does not actually allocate memory for the int32; it creates memory for an address and associates the name myInt32P with that address. The P at the end of the variable name is a convention used in this example to indicate that the variable is a pointer.
The second line creates a block of memory in the data space large enough to hold a single signed 32-bit integer and sets myInt32P to refer to this memory block.
The third line places the value 5 in the memory location to which myInt32P refers. The * operator refers to the value in the address location.
The fourth line sets x equal to the value at address myInt32P plus 7.
Finally, the last line frees the pointer.
The following code is the same example using handles instead of pointers.
int32 **myInt32H;
myInt32H =(int32**)DSNewHandle(sizeof(int32)); **myInt32H = 5;
x = **myInt32H + 7;
...
DSDisposeHandle(myInt32H);
The first line declares the variable myInt32H as a handle to an a signed 32-bit integer. Strictly speaking, this line declares myInt32H as a pointer to a pointer to an int32. As with the previous example, this declaration does not allocate memory for the int32; it creates memory for an address and associates the name myInt32H with that address. The H at the end of the variable name is a convention used in this example to indicate that the variable is a handle.
© National Instruments Corporation |
5-11 |
LabVIEW Code Interface Reference Manual |
