OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [stdlib/] [malloc-standard/] [mallinfo.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/*
2
  This is a version (aka dlmalloc) of malloc/free/realloc written by
3
  Doug Lea and released to the public domain.  Use, modify, and
4
  redistribute this code without permission or acknowledgement in any
5
  way you wish.  Send questions, comments, complaints, performance
6
  data, etc to dl@cs.oswego.edu
7
 
8
  VERSION 2.7.2 Sat Aug 17 09:07:30 2002  Doug Lea  (dl at gee)
9
 
10
  Note: There may be an updated version of this malloc obtainable at
11
           ftp://gee.cs.oswego.edu/pub/misc/malloc.c
12
  Check before installing!
13
 
14
  Hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
15
*/
16
 
17
#include "malloc.h"
18
 
19
 
20
/* ------------------------------ mallinfo ------------------------------ */
21
struct mallinfo mallinfo(void)
22
{
23
    mstate av;
24
    struct mallinfo mi;
25
    int i;
26
    mbinptr b;
27
    mchunkptr p;
28
    size_t avail;
29
    size_t fastavail;
30
    int nblocks;
31
    int nfastblocks;
32
 
33
    LOCK;
34
    av = get_malloc_state();
35
    /* Ensure initialization */
36
    if (av->top == 0)  {
37
        __malloc_consolidate(av);
38
    }
39
 
40
    check_malloc_state();
41
 
42
    /* Account for top */
43
    avail = chunksize(av->top);
44
    nblocks = 1;  /* top always exists */
45
 
46
    /* traverse fastbins */
47
    nfastblocks = 0;
48
    fastavail = 0;
49
 
50
    for (i = 0; i < NFASTBINS; ++i) {
51
        for (p = av->fastbins[i]; p != 0; p = p->fd) {
52
            ++nfastblocks;
53
            fastavail += chunksize(p);
54
        }
55
    }
56
 
57
    avail += fastavail;
58
 
59
    /* traverse regular bins */
60
    for (i = 1; i < NBINS; ++i) {
61
        b = bin_at(av, i);
62
        for (p = last(b); p != b; p = p->bk) {
63
            ++nblocks;
64
            avail += chunksize(p);
65
        }
66
    }
67
 
68
    mi.smblks = nfastblocks;
69
    mi.ordblks = nblocks;
70
    mi.fordblks = avail;
71
    mi.uordblks = av->sbrked_mem - avail;
72
    mi.arena = av->sbrked_mem;
73
    mi.hblks = av->n_mmaps;
74
    mi.hblkhd = av->mmapped_mem;
75
    mi.fsmblks = fastavail;
76
    mi.keepcost = chunksize(av->top);
77
    mi.usmblks = av->max_total_mem;
78
    UNLOCK;
79
    return mi;
80
}
81
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.