<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > MicroBlaze:malloc 函數動(dòng)態(tài)分配內存溢出

MicroBlaze:malloc 函數動(dòng)態(tài)分配內存溢出

作者: 時(shí)間:2017-10-13 來(lái)源:網(wǎng)絡(luò ) 收藏

首先說(shuō)明一點(diǎn), C函數庫支持標準的內存管理函數,如malloc(),calloc(), free(),這些標準的C函數庫定義在libc.a中。動(dòng)態(tài)內存分配從內存的程序的堆(heap)中提供。所以堆的大小會(huì )直接影響調用malloc內存分配的大小。而堆的大小(heap size)是不能在運行的時(shí)候增加,這樣需要在程序編譯的時(shí)候確定合適的堆的大小,在大小可以EDK下generate linker script的時(shí)候,或者直接修改*.ld文件,例如:

本文引用地址:http://dyxdggzs.com/article/201710/365663.htm

_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x1000;
_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x1000;

如果調用malloc(int size)函數的時(shí)候出現,malloc函數返回NULL,這就說(shuō)明內存分配失敗,原因是:

申請的內存的大小可能超過(guò)了內存本身的大小

申請內存的大小超過(guò)了heap_size的大小

針對以上兩個(gè)原因,可以這樣做修改heap_size 和增加實(shí)際的物理內存。

這里要提醒一點(diǎn):每次調用malloc,必須檢查一下返回值,以保證實(shí)際內存分配的請求。

在實(shí)踐中,本人通過(guò)malloc申請一塊近乎3MB內存空間用于存儲圖像數據,但是因為堆設置得太小了,返回值一直為NULL,內存分配失敗。

調用malloc代碼
void *zalloc(unsigned long size)
{
void *ret = malloc(size);
if (ret) memset(ret, 0, size);
return ret;
}



評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>