- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page