This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Dynamic memory usage

I'm trying to use dynamic memory on str912fw44. The code compiles well but when it starts to debug, it gives some error :
"*** error 34: undefined identifier
Non-Aligned Access: Thumb Instruction at 0000C072H, Memory Access at 0000C230H
...
*** error 65: access violation at 0x00080000 : no 'execute/read' permission"

The code I tried was :

ubyte *ptr;
int main()
{ ptr=(ubyte*)calloc(10,sizeof(ubyte));
}

Tools : Keil uVision IDE, Keil Ulink2.

Could you please tell me what could be the problem ?
I don't know where to look. How can I know the size of the memory area used as heap ?

Parents
  • Thank you very much. App data to be hold is very much for each panel, it is why I don't want to define a max statically. I dont use dynamic memory for something else, only one structure will be dynamic.

    There's no point in doing so. It makes no sense. Especially if that is the only place dynamic allocation is used.

    Your program will have to deal with the maximum number of panels attached. That means that the heap must be able to hold the data for the maximum number of panels. The heap is allocated staticially anyway. If you are not using dynamic allocation anywhere else, then it makes no sense to do it here - just allocate memory for the maximum number of panels statically, get rid of the heap, and be done with it.

    Is it not safe ?

    Programs needs to be able to deal with malloc/calloc failing to work, for example. That means having to add extra code for error handling.

Reply
  • Thank you very much. App data to be hold is very much for each panel, it is why I don't want to define a max statically. I dont use dynamic memory for something else, only one structure will be dynamic.

    There's no point in doing so. It makes no sense. Especially if that is the only place dynamic allocation is used.

    Your program will have to deal with the maximum number of panels attached. That means that the heap must be able to hold the data for the maximum number of panels. The heap is allocated staticially anyway. If you are not using dynamic allocation anywhere else, then it makes no sense to do it here - just allocate memory for the maximum number of panels statically, get rid of the heap, and be done with it.

    Is it not safe ?

    Programs needs to be able to deal with malloc/calloc failing to work, for example. That means having to add extra code for error handling.

Children