English 中文(简体)
免费点人使用的长度值
原标题:value of length(integer), used by the free pointer

我们知道,<代码>免费(功能>知道,通过使用在小型点子站后面储存的固定惯性分类值,多少记忆要从小型记忆中解放出来。 因此,我尝试了这一法典,并有两个疑问:

  1. 如果Imalloc( 20 bytes, 然后在减幅点上打印整数值,则显示25个 by。 如果Imalloc( 40 bytes,然后印刷价值,那么我就拿到了49tes!

  2. 如果我试图超越和印刷我的小面积之后的数值,那么每当我获得一个大的惯性价值,储存在最差的记忆之后。 这一价值是什么? 它是特别的吗?

请作任何解释。

int main()
{
    int i;
    int *ptr, *pr;

    ptr = (int *)malloc(20);
    pr = ptr;

    printf("value of ptr is %p", ptr);
    for(i = 0; i < 5; i++) {
        ptr[i] = i + 1;
    }

    printf("now the values in malloc d memory is
");
    for(i = 0; i < 5; i++) {
        printf("%d
", ptr[i]);
    }

    printf("value of ptr is %p
", ptr);
    pr--;
    for(i = 0; i < 20; i++) {
        printf("value of pr at address  %p  is  %d
", pr, *pr);
        pr++;
    }

    return 0;
}
问题回答
  1. 我们不知道中小型公司是如何内部运作的。 图书馆从版本改为运行时间图书馆。 这等于是一夫一妻。

  2. 我们不应取决于任何具体执行的具体后因行为。 仅取决于有文件记载的特征,除非您愿意为某些目的进行一般贸易。

Most malloc implementations do, in fact, allocate an extra few words of overhead immediately before the area given to the program. The overhead allows administrating the heap. But is the size field 4 bytes before, or 16? Is it a 32 bit value? Maybe it is a scaled number of paragraphs (16-byte entries), like on iRMX86. Does the overhead area contain forward links and backward links? Maybe there is a namecheck field with the debug version of the library.

或许可以实施,例如Snobol-68号网络/NOS:一系列结构,有数据点及其规模。 方案“点人”实际上是阵列中该项目的指数。 这是一种特别高效的结构,用于ach和head头目的。

有许多可能的差异,没有一个持久的方案应当依靠这些细节。

可能的话,您可考虑撰写<代码>lengthof(ptr)功能,以列入运行时间的图书馆,该图书馆接收到malloc()或可能实际分配的tes。

也许大多数的<代码>小型执行办法有某种方法可找到点人论点的分量。

然而,这样做的方式是私下的,而有些<条码>小孔执行 don t总是为每个区域分配一个固定头盔<>。

执行<代码>小型<>/代码”的共同点是处理不同分配的大小。 例如,它可以处理不同的问题。

  1. malloc of two words or less (i.e. of 2*sizeof(void*)) since this case is very frequent (for e.g. single-linked list of pointers, like cons cells in Lisp).
  2. malloc of small-sized zones, of size less than a threshold, typically the page size -in the sense of getpagesize(2) syscall on Linux, often 4kbytes.
  3. malloc of large-sized zones, bigger than a page size

有些执行情况考虑到实际地址,例如,设有一个专门供乳房使用的内部领域(页数),另一个专用于面积小区的分配领域:<2条coden 和3*2^n(例如n>2 && n<10),以及实际在各自领域内分配的大型物体。 然后,malloc 执行中,有部分内部的散列表绘图地址(每秒16秒以下,均为零)。

因此,你不应认为每个小区以前都有间接费用。 这可能是错误的。 如果您需要这种假设,则使用操作系统电话(例如mmap(2),就应写上你自己的<代码>。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...