240 likes | 403 Views
Memory Management. Functions. OSMemCreate() Create a partition OSMemGet() Obtaining a memory block OSMemPut() Returning a memory block OSMemQuery() Obtaining status of a memory partition. Memory Control Blocks of μC/OS-II. Memory Partition. Multiple Memory Partitions.
E N D
Functions • OSMemCreate() Create a partition • OSMemGet() Obtaining a memory block • OSMemPut() Returning a memory block • OSMemQuery() Obtaining status of a memory partition
Advantages of μC/OS-II • Disadvantages of malloc() • Fragmentation • Nondeterministic running time • Advantages of μC/OS-II • Avoidance of memory fragmentation • Allocation and deallocation a memory block is done in constant time
OSMemCreate() OSM_MEM *CommTxBuf; INT8U CommTxPart[100][32]; void main() { INT8U err; OSInit(); /*…*/ CommTxBuf = OSMemCreate(CommTxPart, 100, 32, &err) /*…*/ }
OSMemGet() • You must not use more memory than is available form the memory block. • When you are done using the block, you must return it to the proper memory partition. • Pseudo code • Return a memory block • OSMemFreeList should point to the next memory block
OSMemPut() • You should note that OSMemPut() has no way of knowing whether the memory block returned to the partition belongs to that partition.