Most likely it is a bug. I guess it could also be caused by bad power supply, decoupling, noise/spikes/glitches, etc.I dont manage to always reproduce the situation where the code stops running so its very hard for me to know whether this is a bug in code.
The compiler's referring to program memory space, right? So unless the program is writing to its own program memory, it shouldn't be a problem with program memory space. If the problem is caused by "lack of ram", then it's a bug in the program (program shouldn't be trying to use more memory than it has available).Could it be due to memory space?
Most likely it is a bug. I guess it could also be caused by bad power supply, decoupling, noise/spikes/glitches, etc.
The compiler's referring to program memory space, right? So unless the program is writing to its own program memory, it shouldn't be a problem with program memory space. If the problem is caused by "lack of ram", then it's a bug in the program (program shouldn't be trying to use more memory than it has available).
I would assume that it would be trying to allocate RAM.In the code, I use functions like Osal_mem_alloc (a function that allocates space in memory - is it RAM memory?).
It's possible that it's trying to allocate memory that's not available, yes.When you say a bug in code, you mean that I could be using too much of RAM space?
No I did not, What could happen if it returns a NULL but the code behave as if it havent?* did you check for a NULL pointer returned from Osal_mem_alloc and gracefully handle that condition?
Yes I checked it.* did you call Osal_mem_free (with the same pointer returned from Osal_mem_alloc) when you had finished with the particular chunk of memory?
I'll check it out thank you.* did you free any other resources that you allocated (e.g. message buffers, etc.)?
You can trash memory that is used for something else.No I did not, What could happen if it returns a NULL but the code behave as if it havent?
A pointer just holds the address of the memory (it points to (looks at) the allocated memory). If 2 people (A & B) are looking at the same rock, then person A throws it into the sea (person A can no longer see it as it's gone) does person B have to throw the rock also for it to be gone? (sorry, convoluted)Yes I checked it.
However, say that I allocate a memory for pointer A, and then write B = A.
Should I also free B's memory?
The manual that I'm looking at is available from: https://www.electro-tech-online.com/custompdfs/2010/02/OSAL20API_F8W-2003-0002_.pdf, the 'unsigned short' parameter specifies the size of the block of memory that you want to reserve/allocate. This allows you to request up to 65536 bytes of memory; it doesn't mean that there is that much memory available. Also, as this is dynamic (i.e. runtime) memory allocation, the compiler doesn't know how much memory you are asking for (in fact it has no knowledge of what the call to osal_mem_alloc actually does).The Osal_mem_alloc function receives an unsigned short integer.
If the compiler compiles a call to this function, doesnt it mean that you have 'unsigned short'-sized memory space available?
While I'm glad you feel that way, I have no way of solving your specific problem; but I'll answer your questions as I can.Thank you so much friend.
You really helped me out.
Assuming the uC uses a stack, you can subtract the size of the current stack (using the stack pointer) and the size of the heap (which you'd have to keep track of by adding the number of bytes allocated and subtracting the number freed and add any global variables that aren't in the stack) from the total number of bytes available. You may this to be unworkable.Is there any way to know in advance how much memory bytes are left to allocate?
How do you calculate such thing?
void *debug_osal_alloc_mem(uint16 sz)
{
void *ptr = osal_alloc_mem(sz);
if (ptr == NULL)
{
// so the memory _hasn't_ been allocated. So flash an LED or send a serial message
serial_printf("Failed to allocate %d bytes\n", sz);
// you may want to try the following to print out the return address (the address of the call to this function)
// use this line if function pointers are 16 bits
serial_printf("osal_alloc_mem called from 0x%X\n", *((uint16*)(((char*)&sz)+sizeof(sz))));
// or use this line if function pointers are 32 bits
serial_printf("osal_alloc_mem called from 0x%X\n", *((uint32*)(((char*)&sz)+sizeof(sz))));
// you may want to halt execution here...
}
return ptr;
}
that should be if (ptr == NULL)... the if (ptr=NULL) condition
Normally it's due to loops with incorrect logic, or just incorrect logic. Sometimes it can be caused by memory corruption (e.g. buffer under/overruns) and other things that haven't been taken into account.What could cause a code to get stuck?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?