40 likes | 174 Views
Memory Management. Akos Ledeczi EECE 354, Fall 2011 Vanderbilt University. Memory Partitions. Dynamic memory allocation from the heap / malloc () and free()/ can lead to memory fragmentation µC/OS-III provides memory partitions as an alternative
E N D
Memory Management Akos Ledeczi EECE 354, Fall 2011 Vanderbilt University
Memory Partitions • Dynamic memory allocation from the heap /malloc() and free()/ can lead to memory fragmentation • µC/OS-III provides memory partitions as an alternative • Can create multiple partitions with different block sizes
Usage OS_MEM MyPartition; CPU_INT08U Storage[12][100]; /* malloc() also works */ void main() { … OSMemCreate(&MyPartition, “My partition”, (void *)&Storage[0][0], 12,100, &err); … } void MyTask(void *p_arg) { … CPU_INT08U *block = (CPU_INT08U *)OSMemGet(&MyPartition,&err); /* allocate */ if (err == OS_ERR_NONE) { … } … OSMemPut(&MyPartition,block,&err); /* deallocate */ … }
Example • Memory block is not typed: reader and write “agrees” on the content’s format • Once message is written and posted in the queue, originator must not touch it • Once message received and processed, memory block is put back in the partition • To prevent problems if partition runs out of available blocks, a semaphore can be used to control access to it