找到数据段的地址范围 [英] Finding the address range of the data segment

查看:127
本文介绍了找到数据段的地址范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一种编程练习,我在写C.标记 - 清除垃圾收集器我想扫描指针分配的内存中的数据段(全局变量等),但我不知道怎么弄这个段的地址范围。我怎么能这样做呢?

As a programming exercise, I am writing a mark-and-sweep garbage collector in C. I wish to scan the data segment (globals, etc.) for pointers to allocated memory, but I don't know how to get the range of the addresses of this segment. How could I do this?

推荐答案

有关文本的边界(程序code)和数据Linux(和其他Unix系统):

The bounds for text (program code) and data for linux (and other unixes):

#include <stdio.h>
#include <stdlib.h>

/* these are in no header file, and on some
systems they have a _ prepended 
These symbols have to be typed to keep the compiler happy
Also check out brk() and sbrk() for information
about heap */

extern char  etext, edata, end; 

int
main(int argc, char **argv)
{
    printf("First address beyond:\n");
    printf("    program text segment(etext)      %10p\n", &etext);
    printf("    initialized data segment(edata)  %10p\n", &edata);
    printf("    uninitialized data segment (end) %10p\n", &end);

    return EXIT_SUCCESS;
}

如果这些符号来自:<一href=\"http://stackoverflow.com/questions/1765969/unable-to-locate-definition-of-etext-edata-end\">Unable定位ETEXT的定义中,edata,最终

这篇关于找到数据段的地址范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆