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 | |
---|
7 | int _dummy_mstats = 1; |
---|
8 | |
---|
9 | #else |
---|
10 | |
---|
11 | /* |
---|
12 | FUNCTION |
---|
13 | <<mallinfo>>, <<malloc_stats>>, <<mallopt>>---malloc support |
---|
14 | |
---|
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 |
---|
27 | |
---|
28 | SYNOPSIS |
---|
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 | |
---|
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. |
---|
46 | |
---|
47 | <<malloc_stats>> print some statistics about memory allocation on |
---|
48 | standard error. |
---|
49 | |
---|
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. |
---|
57 | |
---|
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. |
---|
61 | |
---|
62 | RETURNS |
---|
63 | <<mallinfo>> returns a mallinfo structure. The structure is defined |
---|
64 | in malloc.h. |
---|
65 | |
---|
66 | <<malloc_stats>> does not return a result. |
---|
67 | |
---|
68 | <<mallopt>> returns zero if the parameter could not be set, or |
---|
69 | non-zero if it could be set. |
---|
70 | |
---|
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. |
---|
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 | |
---|
86 | struct mallinfo |
---|
87 | mallinfo (void) |
---|
88 | { |
---|
89 | return _mallinfo_r (_REENT); |
---|
90 | } |
---|
91 | |
---|
92 | #if !defined (_ELIX_LEVEL) || _ELIX_LEVEL >= 2 |
---|
93 | void |
---|
94 | malloc_stats (void) |
---|
95 | { |
---|
96 | _malloc_stats_r (_REENT); |
---|
97 | } |
---|
98 | |
---|
99 | int |
---|
100 | mallopt (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 | |
---|
116 | void |
---|
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 |
---|
126 | void |
---|
127 | mstats (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) */ |
---|