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.

6.5 Memory Management<br />

6.5.1 CoKmalloc()<br />

Function Prototype:<br />

void* CoKmalloc<br />

(<br />

U32 size<br />

);<br />

Description:<br />

Allocate the size of memory block.<br />

Parameters:<br />

[IN] size<br />

The length of the memory block which need to be allocated with the<br />

unit bytes<br />

Returns:<br />

NULL, Failed to allocate.<br />

Others, Allocate successfully and return the initial address pointer of<br />

the memory block.<br />

Example usage:<br />

#include "CCRTOS.h"<br />

void TaskN (void *pdata)<br />

{<br />

unsigned int *ptr;<br />

...<br />

/* Allocate 20 words of memory block from kernel heap */<br />

ptr = (unsigned int *)CoKmalloc(20*4);<br />

/* process ptr here */<br />

...<br />

/* Release memory block to kernel heap */<br />

CoKfree(ptr);<br />

...<br />

}<br />

Note:<br />

Once you called CoKmalloc(), it will cost 8 bytes to manage this memory<br />

block.<br />

69

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

Saved successfully!

Ooh no, something went wrong!