/*Creates a new native array
You must DISPOSE this object once you don't need it anymore*/
uintptr_t NativeArrayCreateNew(int size)
{
int *workingArray = nullptr;
workingArray = (int*)malloc(sizeof(int) * (size + 1));
workingArray[0] = size;
int i;
for (i = 1; i < size + 1; ++i) {
workingArray[i] = 0;
}
return (uintptr_t)workingArray;
}
//Assigns the given value to the given array index
void NativeArraySetElement(uintptr_t arrayAddress, int position, int value)
{
int *workingArray = (int*)arrayAddress;
workingArray[position + 1] = value;
}
//Obtains the value stored at the given index
int NativeArrayGetElement(uintptr_t arrayAddress, int position)
{
int *workingArray = (int*)arrayAddress;
return workingArray[position + 1];
}
//Obtains the array size
int NativeArrayGetSize(uintptr_t arrayAddress)
{
int *workingArray = (int*)arrayAddress;
return workingArray[0];
}
//Resets the array content
void NativeArrayReset(uintptr_t arrayAddress)
{
int *workingArray = (int*)arrayAddress;
int i;
for (i = 1; i < workingArray[0] + 1; ++i) {
workingArray[i] = 0;
}
}
//Disposes the native array
void NativeArrayDispose(uintptr_t arrayAddress)
{
int *workingArray = (int*)arrayAddress;
free(workingArray);
workingArray = nullptr;
}