📄 ——一种嵌入式系统的内存分配方案.htm
字号:
style="TEXT-INDENT: 30px">◆BufPoolAlloc:从缓冲池中分配一个缓冲区,参数为缓冲池结构指针。如果存在空闲缓冲区,则从空闲链表中除并提供给调用者,执行创建时回调函数。如果回调函数返回错误,则将缓冲区返还给空闲链表。</P>
<P style="TEXT-INDENT: 30px">①检查缓冲池结构中的MAGIC标记是否完好。</P>
<P style="TEXT-INDENT: 30px">②从空闲链表中取出头一个节点。</P>
<P style="TEXT-INDENT: 30px">③如果节点不为空,清空节点,以其地址为参数调用回调函数。</P>
<P style="TEXT-INDENT: 30px">④如果回调函数返回错误,则将节点还给空闲链表。</P>
<P style="TEXT-INDENT: 30px">⑤返回得到空闲缓冲区地址。</P>
<P
style="TEXT-INDENT: 30px">◆BufPoolFree:将缓冲区返回给缓冲池。如果定义了回调函数,将在归还缓冲之间调用回调函数。参数为缓冲池结构和缓冲区指针。</P>
<P style="TEXT-INDENT: 30px">①缓冲池MAGIC标记是否完好。</P>
<P style="TEXT-INDENT: 30px">②如果定义回调函数、调用之。如果返回错误,则设置错误号。</P>
<P style="TEXT-INDENT: 30px">③将缓冲区添加到空闲链表中头部。</P>
<P
style="TEXT-INDENT: 30px">注意该函数有2点:①回调函数返回错误,照样归还缓冲区。②没有检查缓冲区是否二次释放,这一点与Intel的驱动程序不同。</P>
<P
style="TEXT-INDENT: 30px">另外,TMS的缓冲池没有BLOCK要领,不需要判断哪个CELL属于哪个BLOCK,简化
了操作。</P>
<P style="TEXT-INDENT: 0px"><B>5 小结</B></P>
<P
style="TEXT-INDENT: 30px">许多嵌入式应用在RTOS提供的malloc/free的基础上编写自己的内存管理方案。编写这样的内存管理方案,目的无非有两个:一是减少对malloc/free的依赖,从而避免由之带来的内存碎片、时间不确定等总是;另一个是增强程序的查错能力,送还内存使用错误。对于在嵌入式系统中广泛存在的数据库类型的内存需求,即分配多个固定尺寸的内存单元的要求,“一闪分配,多次使用”的方案无疑是一种很好的解决之道。文中介绍的2个例子很好地体现了它的优越性。
</P>
<P></P></DIV></TD></TR>
<TR>
<TD align=middle height=15>
<TABLE cellSpacing=0 cellPadding=0 align=center border=0>
<TBODY>
<TR>
<TD>
<DIV></DIV></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD align=right height=2>
<TABLE cellSpacing=0 cellPadding=0 width="80%" border=0>
<TBODY>
<TR>
<TD width=75>【<A href="javascript:doPrint();">打印本稿</A>】</TD>
<TD width=8></TD>
<TD width=75>
<P>【<A
href="http://www.21ic.com/new_info/news/review.asp?title=一种嵌入式系统的内存分配方案target="
_blank?>发表评论</A>】</P></TD>
<TD width=10></TD>
<TD width=79>【<A
href="http://www.21ic.com/new_info/news/sendmail.asp?num=一种嵌入式系统的内存分配方案">推荐</A>】</TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD align=right height=2></TD></TR>
<TR>
<TD align=right height=2><A href="javascript:window.close();"><IMG
height=20 src="——一种嵌入式系统的内存分配方案.files/close_c.gif" width=77 border=0
name=Image161></A><FONT
color=#ffffff>----</FONT></TD></TR></TBODY></TABLE><BR><BR>
<TABLE cellSpacing=0 cellPadding=0 width=520 align=center border=0>
<TBODY>
<TR>
<TD vAlign=bottom align=middle width=114 bgColor=#999a76
height=1><IMG height=1 src="——一种嵌入式系统的内存分配方案.files/blank.gif"
width=1></TD>
<TD width=466 height=1></TD></TR>
<TR>
<TD align=middle width=114 bgColor=#ece8db height=19>相关新闻</TD>
<TD width=466 height=19></TD></TR>
<TR bgColor=#999a76>
<TD colSpan=2 height=1><IMG height=1
src="——一种嵌入式系统的内存分配方案.files/blank.gif" width=1></TD></TR>
<TR>
<TD colSpan=2 height=1></TD></TR></TBODY></TABLE>
<TABLE borderColor=#000000 cellSpacing=0 cellPadding=0 width=520
align=center border=0>
<TBODY>
<TR>
<TD vAlign=top>
<TABLE class=RelatedTable width="100%" border=0>
<TBODY>
<TR class=RelatedTr>
<TD class=RelatedTd>
<SCRIPT language=javascript
src="——一种嵌入式系统的内存分配方案.files/about.htm"></SCRIPT>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR></TD>
<TD vAlign=top align=middle width=150 bgColor=#ece8db height=2>
<TABLE cellSpacing=0 cellPadding=1 width="100%" border=0>
<TBODY>
<TR>
<TD bgColor=#000000>
<TABLE cellSpacing=0 cellPadding=2 width=150 bgColor=#ece8db
border=0>
<TBODY>
<TR>
<TD>
<META content="Microsoft FrontPage 5.0" name=GENERATOR>
<META content=FrontPage.Editor.Document name=ProgId><BR><A
href="http://www.hhcn.com/chinese/cnindex.html"
target=blank>华恒<BR>(ARM,PowerPC,冷火,龙珠)</A><BR><A
href="http://www.embedon.com/" target=blank>远峰</A> <BR><A
href="http://www.21ic.com/custom/jhb/index.htm"
target=blank>复旦金海博</A><BR><A
href="http://www.emdoor.com/index.asp"
target=blank>亿道</A><BR><BR>单片机 <BR><BR><A
href="http://www.hk.renesas.com/"
target=blank>Renesas</A><BR><A
href="http://www.zlgmcu.com/tools/kaifaban.asp"
target=blank>周立功 Philips</A> <BR><A
href="http://www.strong-ic.com/" target=blank>胜创特</A> <BR><A
href="http://www.holtek.com.tw/" target=blank>盛群 Holtek</A>
<BR><A href="http://www.xhl.com.cn/"
target=blank>Cygnal单片机</A><BR><A href="http://www.lierda.com/"
target=blank>利尔达MSP430</A> <BR><BR>接口电路:<BR><BR><A
href="http://www.whjmw.com/" target=blank>金迈威</A> <BR><A
href="http://www.21ic.com/custom/maiwei/mw.htm"
target=blank>迈威</A> <BR><A href="http://www.rs232.net.cn/"
target=blank>瑞赛特</A><BR><BR><BR>存储器<BR><A
href="http://www.huazhoucn.com/"
target=blank>铁电存储器免费样品</A><BR><BR><BR>模拟器件<BR><A
href="http://www.unique-ap.com.cn/"
target=blank>Linear</A><BR><BR><BR>编程器<BR><A
href="http://www.xeltek.com.cn/"
target=blank>西尔特编程器</A><BR></TD></TR>
<TR>
<TD
height=5></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=766 align=center border=0>
<TBODY>
<TR>
<TD vAlign=top colSpan=6></TD></TR>
<TR>
<TD vAlign=top colSpan=6 height=10></TD></TR>
<TR>
<TD vAlign=top bgColor=#999999 colSpan=6 height=2></TD></TR>
<TR>
<TD class=stxt vAlign=center align=middle colSpan=6
height=6></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=766 align=center border=0>
<TBODY>
<TR>
<TD class=s width=973 height=12></TD></TR>
<TR>
<TD class=s width=973 height=20>
<DIV align=center><FONT face="Arial, Helvetica, sans-serif"><!--start copyright-->
<DIV align=center><FONT color=black>
<TABLE cellSpacing=0 cellPadding=0 width=600 align=center border=0>
<TBODY>
<TR>
<TD align=middle width="100%" colSpan=2><BR>Better View:800*600 Best
View:1024x768 为了本系统能够更好的为您服务,请使用IE4.0或以上版本浏览器
<BR><BR>版权所有(C)21IC中国电子网 电话:010-82357510, 82357511 传真: 010-82357512
</TD></TR></TBODY></TABLE><!--start copyright--></FONT></DIV></FONT></DIV></TD></TR></TBODY></TABLE><BR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -