Вы находитесь на странице: 1из 20

Memory Management

1
Functions
• OSMemCreate()
Create a partition
• OSMemGet()
Obtaining a memory block
• OSMemPut()
Returning a memory block
• OSMemQuery()
Obtaining status of a memory partition

2
Memory Control Blocks of μC/OS-II

3
Memory Partition

4
Multiple Memory Partitions

5
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

6
List of Free Memory Control Blocks

7
OSMemCreate()
OSM_MEM *CommTxBuf;
INT8U CommTxPart[100][32];

void main() {
INT8U err;
OSInit();
/*…*/
CommTxBuf = OSMemCreate(CommTxPart, 100, 32, &err)
/*…*/
}

8
OSMemCreate()

9
OSMemCreate()

10
OSMemCreate()

11
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
1. Return a memory block
2. OSMemFreeList should point to the next
memory block

12
OSMemGet()

13
OSMemPut()
• You should note that OSMemPut() has no way
of knowing whether the memory block
returned to the partition belongs to that
partition.

14
OSMemPut()

15
OS_MemQuery()

16
Using dynamic memory allocation

17
Using dynamic memory allocation

18
A blocking system call

19
A blocking system call

20

Вам также может понравиться