6458|6

73

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

51中使用malloc如何定义内存边界 [复制链接]

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

extern __memt__ _MALLOC_MEM_ __mem_avail__ [];

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

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

我曾经看过一个程序,里面作者非常强,重写了一个malloc函数,他直接定义了一个地址从0x2000开始的2k数组,然后通过一个双向链表实现malloc,如果没有别的办法,看来我也只能重写了,

最新回复

非常感谢三楼。以前没好好看keil c的帮助。  详情 回复 发表于 2009-8-24 09:37
点赞 关注(1)
 

回复
举报

70

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
我觉得链表可能会好点的
 
 

回复

64

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
keil c中malloc函数的实现本身就是用的链表,关键是如何限制链表的启示地址和大小!
 
 
 

回复

63

帖子

0

TA的资源

一粒金砂(初级)

4
 
应该是INIT_MEM.C哪里是初始化,你一定要调用init_mempool()函数:
init_mempool

Summary: #include
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.
 
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

5
 
........
从没试过在51里面用malloc.....
学习.....
 
 
 

回复

84

帖子

0

TA的资源

一粒金砂(初级)

6
 
在51里我也没有用过标准库里的内在管理

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

呵呵

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

具体去看一下那个帮助手册看看
 
 
 

回复

64

帖子

0

TA的资源

一粒金砂(初级)

7
 
非常感谢三楼。以前没好好看keil c的帮助。
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
艾睿电子& Silicon Labs 有奖直播 | 全新蓝牙信道探测:从技术创新到实际应用
直播时间:3月12日(周三)上午10:00
直播奖励:多功能榨汁机、蓝牙音箱、手机支架

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表