Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Labview Code Interface Reference Manual.pdf
Скачиваний:
33
Добавлен:
29.05.2015
Размер:
1.13 Mб
Скачать

Chapter 5 Manager Overview

The following constants define the possible values of the Bool32 data type.

FALSE 0 (int32)

TRUE 1 (int32)

The following constants define the possible values of the LVBoolean data type.

LVFALSE 0 (uInt16)

LVTRUE 0x8000 (uInt16)

Memory Manager

This section describes the memory manager, a set of platform-independent routines for allocating, manipulating, and deallocating memory from external code modules.

Read this section if you need to perform dynamic memory allocation or manipulation from external code modules. If your external code operates on data types other than scalars, you need to understand how LabVIEW manages memory and know the utilities that manipulate data.

Note: For descriptions of specific memory manager functions, see the Function and VI Reference topic in LabVIEW’s Online Reference, or the Code Interface Node Reference online manual.

Memory Allocation

Applications use two types of memory allocation: static and dynamic.

Static Memory Allocation

With static allocation, the compiler determines memory requirements when you create a program. When you launch the program, LabVIEW creates memory for the known global memory requirements of the application. This memory remains allocated while the program runs. This form of memory management is very simple to work with because the compiler handles all the details.

Static memory allocation cannot address the memory management requirements of most real-world applications, however, because you cannot determine most memory requirements until run-time. Also,

© National Instruments Corporation

5-7

LabVIEW Code Interface Reference Manual

Chapter 5 Manager Overview

statically declared memory may result in larger memory requirements, because the memory is allocated for the life of the program.

Dynamic Memory Allocation: Pointers and Handles

With dynamic memory allocation, you reserve memory when you need it, and free memory when you are no longer using it. Dynamic allocation requires more work on your part than static memory allocation, because you have to determine memory requirements and allocate and deallocate memory as necessary.

The LabVIEW memory manager supports two kinds of dynamic memory allocation. The more conventional method uses pointers to allocate memory. With pointers, you request a block of memory of a given size, and the routine returns the address of the block to your CIN. When you no longer need the block of memory, you call a routine to free the block. You can use the block of memory to store data, and you reference that data using the address that the manager routine returned when you created the pointer. You can make copies of the pointer and use them in multiple places in your program to refer to the same data.

Pointers in the LabVIEW memory manager are nonrelocatable, which means that the manager never moves the memory block to which a pointer refers while that memory is allocated for a pointer. This avoids problems that occur when you need to change the amount of memory allocated to a pointer because other references would be out of date. If you need more memory, there might not be sufficient memory to expand the pointer's memory space without moving the memory block to a new location. This would cause problems if an application had multiple references to the pointer, because each pointer refers to the old memory address of the data. Using invalid pointers can cause severe problems.

A second form of memory allocation uses handles to address this problem. As with pointers, when you allocate memory using handles, you request a block of memory of a given size. The memory manager allocates the memory and adds the address of the memory block to a list of master pointers. The memory manager returns a handle that is a pointer to the master pointer. If you reallocate a handle and it moves to another address, the memory manager updates the master pointer to refer to the new address. As long as you look up the correct address using the handle, you access the correct data.

LabVIEW Code Interface Reference Manual

5-8

© National Instruments Corporation

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]