Problem with void CyU3PMemAlloc and void CyU3PMemFree

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
arasc_296896
Level 3
Level 3

 Hi All, 

   

I have been using CyU3PMemAlloc for allocating memory for uint8_t pointers of varying sizes. In case where I use the combination of CyU3PMemAlloc and CyU3PMemFree for each iteration, I am unsure if the used memory is being freed as they doesn't have any return value. The problem is when i use CyU3PMemAlloc for more iterations, it uses adjacent memory locations and at some point it allocates null address to my pointers. 

   

Example :

   

uint8_t *data;

   

data=(uint8_t*)CyU3PMemAlloc(2);

   

CyU3PMemFree(data);

   

I check for a valid pointer by printing &data and checking whether a valid address is allocated. 

   

If anyone had faced the same issue please help.

0 Likes
4 Replies
Anonymous
Not applicable

Hi,

   

 

   

I do not see this problem.

   

Can you send your full code?

   

Btw, you should print data, not &data (to check if valid mem location is being allocated to the pointer). Maybe this is the issue in your code?

   

 

   

-Shashank

0 Likes
arasc_296896
Level 3
Level 3

I print &data[0] and it yeilds the same result while we print data. I can't send you the full code but I have explained the scenario. 

   

Example :

   

function()

   

{

   

uint8_t *data;

   

data=(uint8_t*)CyU3PMemAlloc(2);

   

        CyU3PI2cTransmitBytes(&preamble,data,count,3);

   

        CyU3PMemFree(data);

   

}

   

When I call this function over and over again and after a while my  CyU3PI2cTransmitBytes failed returning error code stating a null pointer has been passed. When I checked by printing the address allocated to variable data, I found it was the one with null reference. 

   

I know that there is a limit for allocating heap memory but as I free the memory each time I should not get any issues I suppose. 

0 Likes
arasc_296896
Level 3
Level 3

 You can recreate it by implementing the above function in any of your examples in the sdk. Print the allocated address and the return type of i2ctransmitbytes api !

0 Likes
arasc_296896
Level 3
Level 3

 Hi..  Did you manage to recreate it ?

0 Likes