- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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 kopiert
1 Antworten
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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
Antworten
Themen-Optionen
- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite