|
发表于 2008-8-18 00:36:08
|
显示全部楼层
看到这么复杂的中断程序,先晕2分钟
。
。
。
贴出ICC的帮助
􀀗 void *malloc(size_t size)
allocates a memory chunk of size size from the heap. It returns 0 if it cannot
honor the request.
􀀗 void _NewHeap(void *start, void *end)
initializes the heap for memory allocation routines. malloc and related routines
manage memory in the heap region. See Program Areas for information on
memory layout. A typical call uses the address of the symbol _bss_end+1 as the
“start” value. The symbol _bss_end defines the end of the data memory used by
the compiler for global variables and strings. You add 1 to it since the Stack
Checking Functions use the byte at _bss_end to store a sentinel byte. The “end”
value must not run into the stacks.
extern char _bss_end;
_NewHeap(&_bss_end+1, &_bss_end + 201); // 200 bytes heap
Be aware that for a microcontroller with a small amount of data memory, it is often
not feasible or wise to use dynamic allocation due to its overhead and potential for
memory fragmentation. Often a simple statically allocated array serves one’s
needs better.
说说我的猜想,可能是内存分配链表被中断程序保护了,所以,每次分配完毕,中断退出后,又还原了。也就是说malloc不是一个可以重入的函数
我从来不用这个函数,因为消耗资源,不如自行编写一个内存管理器,更好更安全 |
|