Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdlib / mstats.c
blob85c20f1bc0ef2c543990f262f8abef88b5230359
1 /* VxWorks provides its own version of malloc, and we can't use this
2 one because VxWorks does not provide sbrk. So we have a hook to
3 not compile this code. */
5 #ifdef MALLOC_PROVIDED
7 int _dummy_mstats = 1;
9 #else
12 FUNCTION
13 <<mallinfo>>, <<malloc_stats>>, <<mallopt>>---malloc support
15 INDEX
16 mallinfo
17 INDEX
18 malloc_stats
19 INDEX
20 mallopt
21 INDEX
22 _mallinfo_r
23 INDEX
24 _malloc_stats_r
25 INDEX
26 _mallopt_r
28 SYNOPSIS
29 #include <malloc.h>
30 struct mallinfo mallinfo(void);
31 void malloc_stats(void);
32 int mallopt(int <[parameter]>, <[value]>);
34 struct mallinfo _mallinfo_r(void *<[reent]>);
35 void _malloc_stats_r(void *<[reent]>);
36 int _mallopt_r(void *<[reent]>, int <[parameter]>, <[value]>);
38 DESCRIPTION
39 <<mallinfo>> returns a structure describing the current state of
40 memory allocation. The structure is defined in malloc.h. The
41 following fields are defined: <<arena>> is the total amount of space
42 in the heap; <<ordblks>> is the number of chunks which are not in use;
43 <<uordblks>> is the total amount of space allocated by <<malloc>>;
44 <<fordblks>> is the total amount of space not in use; <<keepcost>> is
45 the size of the top most memory block.
47 <<malloc_stats>> print some statistics about memory allocation on
48 standard error.
50 <<mallopt>> takes a parameter and a value. The parameters are defined
51 in malloc.h, and may be one of the following: <<M_TRIM_THRESHOLD>>
52 sets the maximum amount of unused space in the top most block before
53 releasing it back to the system in <<free>> (the space is released by
54 calling <<_sbrk_r>> with a negative argument); <<M_TOP_PAD>> is the
55 amount of padding to allocate whenever <<_sbrk_r>> is called to
56 allocate more space.
58 The alternate functions <<_mallinfo_r>>, <<_malloc_stats_r>>, and
59 <<_mallopt_r>> are reentrant versions. The extra argument <[reent]>
60 is a pointer to a reentrancy structure.
62 RETURNS
63 <<mallinfo>> returns a mallinfo structure. The structure is defined
64 in malloc.h.
66 <<malloc_stats>> does not return a result.
68 <<mallopt>> returns zero if the parameter could not be set, or
69 non-zero if it could be set.
71 PORTABILITY
72 <<mallinfo>> and <<mallopt>> are provided by SVR4, but <<mallopt>>
73 takes different parameters on different systems. <<malloc_stats>> is
74 not portable.
78 #include <_ansi.h>
79 #include <reent.h>
80 #include <stdlib.h>
81 #include <malloc.h>
82 #include <stdio.h>
84 #ifndef _REENT_ONLY
86 struct mallinfo
87 mallinfo (void)
89 return _mallinfo_r (_REENT);
92 #if !defined (_ELIX_LEVEL) || _ELIX_LEVEL >= 2
93 void
94 malloc_stats (void)
96 _malloc_stats_r (_REENT);
99 int
100 mallopt (int p,
101 int v)
103 return _mallopt_r (_REENT, p, v);
106 #endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 2 */
108 #endif
110 #if !defined (_ELIX_LEVEL) || _ELIX_LEVEL >= 2
112 /* mstats is now compatibility code. It used to be real, for a
113 previous version of the malloc routines. It now just calls
114 malloc_stats. */
116 void
117 _mstats_r (struct _reent *ptr,
118 char *s)
120 _REENT_SMALL_CHECK_INIT(ptr);
121 fiprintf (_stderr_r (ptr), "Memory allocation statistics %s\n", s);
122 _malloc_stats_r (ptr);
125 #ifndef _REENT_ONLY
126 void
127 mstats (char *s)
129 _mstats_r (_REENT, s);
132 #endif
134 #endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 2 */
136 #endif /* ! defined (MALLOC_PROVIDED) */