- FreeMode
- FreeMode
- Reserve
- Resize
- Clear
- Shutdown
- CreateElement
- Add
- AddArray
- Insert
- InsertArray
- AssignArray
- Update
- Shift
- Detach
- Delete
- DeleteRange
- At
- CompareArray
- InsertSort
- Search
- SearchGreat
- SearchLess
- SearchGreatOrEqual
- SearchLessOrEqual
- SearchFirst
- SearchLast
- Save
- Load
- Type
CArrayObj
CArrayObj class is a class of dynamic array of pointers to instances of CObject and its derived classes.
Description
Class CArrayObj provides the ability to work with a dynamic array of pointers to instances of CObject and its derived classes. This allows working both with multidimensional dynamic arrays of primitive data types and with data structures that have more complex organization of data.
The class allows adding/inserting/deleting array elements, performing an array sorting, and searching in a sorted array. In addition, methods of working with files have been implemented.
There are certain subtleties of the class CArrayObj.
Declaration
class CArrayObj : public CArray |
Title
#include <Arrays\ArrayObj.mqh> |
Inheritance hierarchyCArrayObj Direct descendants |
Class Methods by Groups
Attributes |
|
---|---|
Gets the flag of memory management |
|
Sets the flag of memory management |
|
Memory control |
|
Allocates memory to increase the size of the array |
|
Sets a new (smaller) size of the array |
|
Clears the array with full deallocation of its memory (but not its elements). |
|
Creating a new element |
|
virtual CreateElement |
Creates a new array element in the specified position |
Add methods |
|
Adds an element to the end of the array |
|
Adds an element to the end of the array |
|
Inserts an element to the specified position in the array |
|
Inserts to an array elements from another array from the specified position |
|
Copies the elements of one array to another |
|
Update methods |
|
Changes the element at the specified position array |
|
Moves an item from a given position in the array to the specified offset |
|
Delete methods |
|
Gets the element from the specified position and removes it from the array |
|
Removes the element from the specified array position |
|
Deletes a group of elements from the specified array position |
|
Removes all elements of the array without the release of the array memory |
|
Access methods |
|
Gets the element from the specified array position |
|
Compare methods |
|
Compares the array with another one |
|
Sorted array operations |
|
Inserts an element in a sorted array |
|
Searches for an element equal to the sample in the sorted array |
|
Searches for an element with a value exceeding the value of the sample in the sorted array |
|
Searches for an element with a value less than the value of the sample in the sorted array |
|
Searches for an element with a value greater than or equal to the value of the sample in the sorted array |
|
Searches for an element with a value less than or equal to the value of the sample in the sorted array |
|
Searches for the first element equal to the sample in the sorted array |
|
Searches for the last element equal to the sample in the sorted array |
|
Input/output |
|
Saves data array in the file |
|
Loads data array from the file |
|
Gets the type identifier of the array |
Methods inherited from class CObject Prev, Prev, Next, Next, Compare |
---|
Methods inherited from class CArray Step, Step, Total, Available, Max, IsSorted, SortMode, Clear, Sort |
Arrays of the CObject class have practical application (including all classes of the Standard Library).
For example, consider the options for two-dimensional array:
#include <Arrays\ArrayDouble.mqh>
|
Subtleties #
The class has a mechanism to control dynamic memory, so be careful when working with elements of the array.
Mechanism of memory management can be switched on/off using the method FreeMode (bool). By default, the mechanism is enabled.
Accordingly, there are two options for dealing with the CArrayObj class:
1. Mechanism of memory management is enabled. (default)
In this case, CArrayObj takes responsibility for releasing the memory used for the elements after their removal from the array. A custom program should not release the array elements.
Example:
int i;
|
2. Mechanism of memory management is disabled.
In this case, CArrayObj is not responsible for deallocating of the elements' memory after their removal from the array. Besides, the user program must deallocate the array elements.
Example:
int i;
|