51中使用malloc如何定义内存边界

zhoushunda960 2009-08-21 03:36:41
有个问题想问一下大家:
在keilc\C51\LIB里的malloc.c不知道大家看过没有?里面有这样一些定义:

extern __memt__ _MALLOC_MEM_ __mem_avail__ [];

根据后面的代码,我觉得__mem_avail__ []应该是代表内存边界,但在这里定义的是一个外部变量,不知道它到底的范围是多少?是不是从0x0000开始的地址?或者是从设置里可以设置?

因为我最近要做的一个项目中,希望在内存动态分配时,能跳过一些地址(这些地址用作其它器件连接用)。非常希望大家不吝赐教。

我曾经看过一个程序,里面作者非常强,重写了一个malloc函数,他直接定义了一个地址从0x2000开始的2k数组,然后通过一个双向链表实现malloc,如果没有别的办法,看来我也只能重写了,
...全文
514 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoushunda960 2009-08-24
  • 打赏
  • 举报
回复
非常感谢三楼。以前没好好看keil c的帮助。
lbing7 2009-08-23
  • 打赏
  • 举报
回复
在51里我也没有用过标准库里的内在管理

只在公司一个项目中自己弄了一个简单的定长内在管理库

呵呵

在看文档的时候,说是51标准库里在用MALLOC前必须定义一下内存空间.

具体去看一下那个帮助手册看看
Great_Bug 2009-08-22
  • 打赏
  • 举报
回复
........
从没试过在51里面用malloc.....
学习.....
schlafenhamster 2009-08-22
  • 打赏
  • 举报
回复
应该是INIT_MEM.C哪里是初始化,你一定要调用init_mempool()函数:
init_mempool

Summary: #include <stdlib.h>
void init_mempool (
void xdata *p, /* start of memory pool */
unsigned int size); /* length of memory pool */

Description: The init_mempool function initializes the memory
management routines and provides the starting address and
size of the memory pool. The p argument points to a
memory area in xdata which is managed using the calloc,
free, malloc, and realloc library functions. The size
argument specifies the number of bytes to use for the
memory pool.

NOTE
This function must be used to setup the memory pool before
any other memory management functions (calloc, free,
malloc, realloc) can be called. Call the init_mempool
function only once at the beginning of your program.
Source code is provided for this routine in the folder
\KEIL\C51\LIB. You can modify the source to customize this
function for your hardware environment. Refer to
“Chapter 6. Advanced Programming Techniques” on page
149 for more information.
Return Value: None.
zhoushunda960 2009-08-22
  • 打赏
  • 举报
回复
keil c中malloc函数的实现本身就是用的链表,关键是如何限制链表的启示地址和大小!
fendou_mo 2009-08-22
  • 打赏
  • 举报
回复
我觉得链表可能会好点的

27,375

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧