cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
597 Views
Registered: ‎08-01-2017

Bad_allock with list

Greetings!

 

I am using Zynq-7000 and trying to work with list (by including <list> in c++ project) using only pop_front() and push_back() functions. At different time of work I have bad_allock error, which kills my programm. I tryed to make error on small project, using only those functions and see what happened:

#include <list>
#include <stdio.h>
#include "xtime_l.h"
#include "xil_exception.h"
using namespace std;
class point
{
public:
	double X;
	double Y;
	double Z;
	point() {}
	point(double x, double y, double z) {X = x; Y = y; Z = z;}
};
list<point> mylist;
XTime time;
static void DataAbortIntrHandler(void *CallBackRef)
{

unsigned int addr;
                __asm__ __volatile__("\n\ldr %0, [sp,#44]"  : "=r" (addr));
                printf("instruction address causing data abort is %x\n",addr-8);
                while(1);
}

int main()
{
	int size;
	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_DATA_ABORT_INT,
	    (Xil_ExceptionHandler)DataAbortIntrHandler,
	    NULL);
	while(1)
	{
		size = mylist.size();
		printf("%d size\n", size);
		XTime_GetTime(&time);
		if(size < 1000 && (time % 2 || size == 0))
			mylist.push_back(point(1.2, 2.3, 4.6));
		else
		{
			if(size != 0)
				mylist.pop_front();
		}
	}
	return 0;
}

I used time to get random in functions and made defence to don't allow push_back if size of list is more than 1000 and pop_front if there isn't any elements in list. On COM I see:

ListError

Can anyone say what is wrong or what can I do to bypass memory error with list?

Thanks for help!

0 Kudos
1 Reply
Highlighted
Visitor
Visitor
574 Views
Registered: ‎08-01-2017

Addition: on core 1 error need less time to arise.

0 Kudos