Facing an issue regarding NRF MEMORY MANAGEMENT(Code Restarts while assigning values to allocated mem)

Hi, I am using the nrf mem_manager library for allocationg multiple dynamic memories in my code. I have done the following


typedef struct
	uint8_t b_data[31];
	uint8_t id_no;

devicetype * device1_database;
devicetype * device2_database;
devicetype * device3_database;
devicetype * device4_database;

if((device1_database = nrf_malloc(15)) == NULL)
        printf("not alocated device1_database\n");
    	 printf("success device1\n");
if((device2_database = nrf_malloc(15)) == NULL)
        printf("not alocated device2_database\n");
    	 printf("success device2\n");
if((device3_database = nrf_malloc(15)) == NULL)
        printf("not alocated device3_database\n");
    	 printf("success device3\n");
if((device4_database = nrf_malloc(15)) == NULL)
        printf("not alocated device4_database\n");
    	 printf("success device4\n");    	 

All the devices are getting the allocation for the memory as I am getting success prints ... But while filling the data to these values , the first two dynamically allocated memories (i.e. device1_database,device2_database )get filled with proper data and while filling the third allocated memory (i.e. device3_database) the code restarts . The code snippet of filling the data is shown below:

		for(int i = 0; i < 15;i++)
		 device1_database[0].b_data[i] =  RAW_device_Data[i];

 Can anyone help me understand what is making the code to restart?

  • Hi

    Are you able to check the memory addresses written to the 4 devicetype pointers after you have run the calls to nrf_malloc(..) ?

    If the code crashes when you try to write to one of the pointers it indicates that it has an invalid memory address. 

    Are you running the code on a standard nRF52DK?

    Best regards