this is my first post, so sorry if it is not asked well.
Basically I am having trouble with dynamic memory and i would like to know if it is me misunderstanding the concept, or at least one of the functions. Ok, so i'm using C++ where I need to manage an array that changes size within the main program loop but i keep getting a heap error when i try to delete the memory. (below is a simplified version of what i'm trying to do).
void main(void)
{
//Initialization
//main loop
while(true)
{
int* array;
function(&array);
printf("test %d",array[0]); //basically use the data
delete [] array;
}
}
//in separate file
void function(**int val)
{
*val=new int[size of array] // i pass the size of the array...
//to the function as well
//fill the array with data
return;
}
Ok so after this i can read the data so it must be attached to the pointer "array" but then why would it not allow me to delete the data as if it was already deleted?
Any advice would be much appreciated thanx.