01-12-2010 04:17 PM
Hi,
Im in the process of adding an ActiveX 3D graph to an application I use. I never know the number of data points I will have to graph ahead of time so I have been creating a 2D array with :
double **Data; Data = malloc(size_x * sizeof(double *)); for (i = 0; i < size_x; i++) { Data[i] = malloc(size_y * sizeof(double)); }
my problem comes when I try to use CA_VariantSet2DArray, I always get the Array arguement too small runtime error. My best guess is that the space allocated in the array is not contiguous, but Im not sure. I have not been able to resolve the issue. Can anyone help me convert my 2D array to a Variant either the way I have it or suggest a better way to declare a dynamic 2D array that will work with CA_VariantSet2DArray?
Solved! Go to Solution.
01-13-2010 11:00 AM
Hunter,
Your hunch is correct. You do have to have a contiguous block of memory to pass to this function. Passing the size_x and size_y allows the function to make your contiguous block into a 2d array. Declare your array as such:
Data = malloc(size_x * size_y * sizeof(double));
Then you can pass this to the function and hvae it create the variant as expected. However, when you directly access Data, note that you can't use the Data[2][3] shorthand anymore, and you'll have to do some pointer arithmetic to access elements of the array.
01-13-2010 11:42 PM
11-09-2011 07:55 PM
I have been experiencing the same problem. Even though the topic has been solved a while ago, I was wondering if somebody could post a sample code that would solve this problem. My background is in mechanical engineering, so I only use C as a tool and my knowledge seems to be limited in this area. I would also appreciate a few references where I could learn more about this topic.
Thank you in advance.
Regards,
Salim