Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

memory allocation

yoo__jungmin
Beginner
318 Views
I wrote a sample code to test mkl_malloc as below.
When I run this code, I encounted memory error. 
Could somebody explain to me why this happened and how to slove this problem??
 
typedef struct _a_
{
	int *data;
	_a_()
	{
		data = (int *)mkl_malloc(10 * sizeof(int), 32);
		for (int i = 0; i < 10; i++)
		{
			data = i;
		}
	}
	
	~_a_()
	{
		mkl_free(data);
	}
}a_;

int main(void)
{
	a_ *b;
	b = (a_ *)mkl_malloc(10 * sizeof(a_), 32);

	std::cout << b[0].data[0] << std::endl;


	mkl_free(b);
	return 0;
}
0 Kudos
1 Reply
Pamela_H_Intel
Moderator
318 Views

Jungmin,

I can't say for sure because I need to know what the error was and which line it refers to. You may be getting the error because you declared data as a pointer but are attempting to traverse it as if it were an array. If you tell me what the error is I can be more certain.

Pamela

0 Kudos
Reply