Detailed Description
Structure containing memory allocated to store a variable.
Terms
Data : a structure containing memory allocated to a certain item. This can be of any type.
Introduction
A Data structure contains memory allocated for the purpose of storing a variable. This differs from a direct pointer in that the memory can be reused for another purpose. By keeping track of how much data has been allocated, the same allocation can be reused if memory of equal or smaller size is needed, otherwise more memory can be automatically allocated in the same method call.
Creation
A Data structure does not need to be created by a method, it only needs to be allocated in memory. However, it does need to be reset before any operations are carried out with it.
Allocation
To allocate memory for a variable in a Data structure, the fiftyoneDegreesDataMalloc method can be called in a similar way to the standard malloc method. Any existing variable in the Data structure will either be overwritten by the new variable, or the previous variable will be freed and new memory allocated.
Example Usage
Collaboration diagram for Data:
Structs | |
| struct | fiftyoneDegreesData |
| Data structure used for reusing memory which may have been allocated in a previous operation. More... | |
Typedefs | |
| typedef unsigned char | byte |
| Alias for unsigned char. | |
Functions | |
| void | fiftyoneDegreesDataReset (fiftyoneDegreesData *data) |
| Resets the data structure ready for a new operation. | |
| void * | fiftyoneDegreesDataMalloc (fiftyoneDegreesData *data, size_t bytesNeeded) |
| Ensures the data structure contains sufficient bytes. | |
Function Documentation
◆ fiftyoneDegreesDataMalloc()
| void * fiftyoneDegreesDataMalloc | ( | fiftyoneDegreesData * | data, |
| size_t | bytesNeeded ) |
Ensures the data structure contains sufficient bytes.
If insufficient bytes are available then the current memory is freed and a new block of memory is allocated.
- Parameters
-
data pointer to the data structure to be checked for sufficient bytes bytesNeeded the number of bytes the data needs to be able to store
- Returns
- a pointer to the memory held within data
◆ fiftyoneDegreesDataReset()
| void fiftyoneDegreesDataReset | ( | fiftyoneDegreesData * | data | ) |
Resets the data structure ready for a new operation.
MUST be called before using an instance of fiftyoneDegreesData.
- Parameters
-
data to be reset
