Sollte die dynamische Speicherzuweisung (new/malloc) im Interrupt erfolgen?C++

Programme in C++. Entwicklerforum
Anonymous
 Sollte die dynamische Speicherzuweisung (new/malloc) im Interrupt erfolgen?

Post by Anonymous »

Ich mache eingebettete Programmierung (mit stm32f407-Chip).
in usb_otg_fs(interrupt) lese ich Daten und ordne 8 Bytes dynamisch zu (und schreibe 8 Bytes hinein), aber das Problem ist, dass es manchmal bei new/malloc/delete/free fehlschlägt, ich viel Zeit gebraucht habe, um den Code zu überprüfen, und ich bin sicher, dass mein Heap-Speicher noch nicht aufgebraucht ist 30 %.
Die Sache ist, dass es manchmal bei der Funktion main() an neuen/malloc/delete/free-Speicherorten
code main()
fehlschlägt

Code: Select all

while (1)
{
int r =1000;  // số ngẫu nhiên 0..200

const uint32_t ran_1 =(rand() % r) +1;
uint8_t *p = (uint8_t*)malloc(ran_1);
const uint32_t ran_2 =(rand() % r) +1;
uint8_t *p1 = (uint8_t*)malloc(ran_2);
const uint32_t ran_3 =(rand() % r) +1;
uint8_t *p2 = (uint8_t*)malloc(ran_3);
const uint32_t ran_4 =(rand() % r) +1;
uint8_t *p3 = (uint8_t*)malloc(ran_4);
const uint32_t ran_5 =(rand() % r) +1;
uint8_t *p4 = (uint8_t*)malloc(ran_5);
const uint32_t ran_6 =(rand() % r) +1;
uint8_t *p5 = (uint8_t*)malloc(ran_6);
free(p);
free(p1);
free(p2);
free(p3);
free(p4);
free(p5);
}
Ich habe versucht, den Interrupt zu deaktivieren und einfach den Code in main() auszuführen, und es hat gut funktioniert.
Ich frage mich, ob die dynamische Speicherzuweisung im Interrupt eine gute Idee ist oder nicht und warum?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post