02.01.2015 Views

CooCox CoOS User's Guide

CooCox CoOS User's Guide

CooCox CoOS User's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>CooCox</strong> <strong>CoOS</strong> can manage a total of 32 fixed-length partitions of different<br />

size. You can create a partition of fixed length by calling<br />

CoCreateMemPartition(). After being created successfully, you can allocate or<br />

release the memory block by calling CoGetMemoryBuffer() and<br />

CoFreeMemoryBuffer(). You can also get the number of free memory blocks in<br />

current memory partition by calling CoGetFreeBlockNum().<br />

Code 2 The creation and use of fixed-length partition<br />

U8 memPartition[128*20];<br />

OS_MMID memID;<br />

void myTask (void* pdata)<br />

{<br />

U8* data;<br />

memID = CoCreateMemPartition(memPartition,128,20);<br />

if(CoGetFreeBlockNum(memID ) != 0)<br />

{<br />

data = (U8*)CoGetMemoryBuffer(memID );<br />

}<br />

..................<br />

CoFreeMemoryBuffer(memID ,data);<br />

}<br />

4.2.2 Variable-length partition<br />

From the implement of conventional dynamic memory shown above, we<br />

can see that it need to operate the free list and the allocated list at the same<br />

time while release the memory, which require a long operation time and has<br />

impaction to the CPU. For these reasons, <strong>CooCox</strong> <strong>CoOS</strong> redesigns the list to<br />

ensure that both the allocation and release of memory only require to search<br />

just one list.<br />

Free list<br />

head<br />

NULL<br />

1 2 3 4<br />

NULL<br />

Allocated list<br />

Figure 4.2.3 List of variable-length partition<br />

From the figure we can see that all the free memory in the system can<br />

separately form a one-way list so that it is more convenient to look up the list<br />

28

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!