source: trunk/libs/newlib/src/newlib/libc/stdlib/mstats.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.1 KB
Line 
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.  */
4
5#ifdef MALLOC_PROVIDED
6
7int _dummy_mstats = 1;
8
9#else
10
11/*
12FUNCTION
13<<mallinfo>>, <<malloc_stats>>, <<mallopt>>---malloc support
14
15INDEX
16        mallinfo
17INDEX
18        malloc_stats
19INDEX
20        mallopt
21INDEX
22        _mallinfo_r
23INDEX
24        _malloc_stats_r
25INDEX
26        _mallopt_r
27
28SYNOPSIS
29        #include <malloc.h>
30        struct mallinfo mallinfo(void);
31        void malloc_stats(void);
32        int mallopt(int <[parameter]>, <[value]>);
33
34        struct mallinfo _mallinfo_r(void *<[reent]>);
35        void _malloc_stats_r(void *<[reent]>);
36        int _mallopt_r(void *<[reent]>, int <[parameter]>, <[value]>);
37
38DESCRIPTION
39<<mallinfo>> returns a structure describing the current state of
40memory allocation.  The structure is defined in malloc.h.  The
41following fields are defined: <<arena>> is the total amount of space
42in 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
45the size of the top most memory block.
46
47<<malloc_stats>> print some statistics about memory allocation on
48standard error.
49
50<<mallopt>> takes a parameter and a value.  The parameters are defined
51in malloc.h, and may be one of the following: <<M_TRIM_THRESHOLD>>
52sets the maximum amount of unused space in the top most block before
53releasing it back to the system in <<free>> (the space is released by
54calling <<_sbrk_r>> with a negative argument); <<M_TOP_PAD>> is the
55amount of padding to allocate whenever <<_sbrk_r>> is called to
56allocate more space.
57
58The alternate functions <<_mallinfo_r>>, <<_malloc_stats_r>>, and
59<<_mallopt_r>> are reentrant versions.  The extra argument <[reent]>
60is a pointer to a reentrancy structure.
61
62RETURNS
63<<mallinfo>> returns a mallinfo structure.  The structure is defined
64in malloc.h.
65
66<<malloc_stats>> does not return a result.
67
68<<mallopt>> returns zero if the parameter could not be set, or
69non-zero if it could be set.
70
71PORTABILITY
72<<mallinfo>> and <<mallopt>> are provided by SVR4, but <<mallopt>>
73takes different parameters on different systems.  <<malloc_stats>> is
74not portable.
75
76*/
77
78#include <_ansi.h>
79#include <reent.h>
80#include <stdlib.h>
81#include <malloc.h>
82#include <stdio.h>
83
84#ifndef _REENT_ONLY
85
86struct mallinfo
87mallinfo (void)
88{
89  return _mallinfo_r (_REENT);
90}
91
92#if !defined (_ELIX_LEVEL) || _ELIX_LEVEL >= 2
93void
94malloc_stats (void)
95{
96  _malloc_stats_r (_REENT);
97}
98
99int
100mallopt (int p,
101        int v)
102{
103  return _mallopt_r (_REENT, p, v);
104}
105
106#endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 2 */
107
108#endif
109
110#if !defined (_ELIX_LEVEL) || _ELIX_LEVEL >= 2
111
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.  */
115
116void
117_mstats_r (struct _reent *ptr,
118        char *s)
119{
120  _REENT_SMALL_CHECK_INIT(ptr);
121  fiprintf (_stderr_r (ptr), "Memory allocation statistics %s\n", s);
122  _malloc_stats_r (ptr);
123}
124
125#ifndef _REENT_ONLY
126void
127mstats (char *s)
128{
129  _mstats_r (_REENT, s);
130}
131
132#endif
133
134#endif /* !_ELIX_LEVEL || _ELIX_LEVEL >= 2 */
135
136#endif /* ! defined (MALLOC_PROVIDED) */
Note: See TracBrowser for help on using the repository browser.