Let's assume the following:
typedef
{
float Floats[1000];
int Used;
} T_MY_ARRAY;
float Some_Function(T_MY_ARRAY * Data)
{
float Result;
int Counter;
// Add the values together
for(Counter = 0, Result = 0.0;Counter < Data->Used;Counter++)
{
Result += Data->Floats[Counter];
}
return(result);
}
Now, by declaring
T_MY_ARRAY The_Block;
you creats The_Block from the heap, this can be OK for smaller memory chunks but should be avoided for large chunks.
To access the content you use The_Block.Floats[x] and The_Block.Used.
To call Some_Function do like this:
x = Some_Function(&The_Block);
Then You can declare
T_MY_ARRAY * The_Block;
which just means that you has declared a pointer to a block of that type/size, currently pointing to nothing.
Now you has to make it point on something:
The_Block = new T_MY_ARRAY;
At this point, if The_Block == null you has an error, no memory could be assigned.
If everything goes OK you access the content by using The_Block->Floats[x] and The_Block->Used.
To call Some_Function do it like this:
x = Some_Function(The_Block);
Remember to free The_Block when you're finished with it:
delete The_Block; // Frees the memory taken
The_Block = null; // Catches unauthorized uses after deletion, just a good idea
Totte