I am calling a function that dynamically allocates memory for some arrays using new, and then fills the arrays with values. It is my understanding that once the function exits, the memory and values should persist and that I should be able to access the values in other parts of my program. However, after the function exits, when I try to access the arrays, I get the message 'Access violation at address...'. Can anyone give me some advice on why this is happening and how I can fix it? Thanks a lot.
I am using Borland C++ Builder 5.0 on Windows XP pro.
Here's some sample code:
float *data, buff;
size = get_data_size(&infile);
fill_data_array(&infile, data, size);
buff = data; //this is where access violation occurs
//function is defined in header.h
void fill_data_array(ifstream *infile, float *data, int size)
data = new float[size];
for(int i=0; i<size; i++)
... //do stuff with infile to fill data