1MALLOC_GET_STATE(3) Linux Programmer's Manual MALLOC_GET_STATE(3)
2
3
4
6 malloc_get_state, malloc_set_state - record and restore state of malloc
7 implementation
8
10 #include <malloc.h>
11
12 void* malloc_get_state(void);
13
14 int malloc_set_state(void *state);
15
17 Note: these function are removed in glibc version 2.25.
18
19 The malloc_get_state() function records the current state of all mal‐
20 loc(3) internal bookkeeping variables (but not the actual contents of
21 the heap or the state of malloc_hook(3) functions pointers). The state
22 is recorded in a system-dependent opaque data structure dynamically
23 allocated via malloc(3), and a pointer to that data structure is
24 returned as the function result. (It is the caller's responsibility to
25 free(3) this memory.)
26
27 The malloc_set_state() function restores the state of all malloc(3)
28 internal bookkeeping variables to the values recorded in the opaque
29 data structure pointed to by state.
30
32 On success, malloc_get_state() returns a pointer to a newly allocated
33 opaque data structure. On error (for example, memory could not be
34 allocated for the data structure), malloc_get_state() returns NULL.
35
36 On success, malloc_set_state() returns 0. If the implementation
37 detects that state does not point to a correctly formed data structure,
38 malloc_set_state() returns -1. If the implementation detects that the
39 version of the data structure referred to by state is a more recent
40 version than this implementation knows about, malloc_set_state()
41 returns -2.
42
44 For an explanation of the terms used in this section, see
45 attributes(7).
46
47 ┌────────────────────┬───────────────┬─────────┐
48 │Interface │ Attribute │ Value │
49 ├────────────────────┼───────────────┼─────────┤
50 │malloc_get_state(), │ Thread safety │ MT-Safe │
51 │malloc_set_state() │ │ │
52 └────────────────────┴───────────────┴─────────┘
53
55 These functions are GNU extensions.
56
58 These functions are useful when using this malloc(3) implementation as
59 part of a shared library, and the heap contents are saved/restored via
60 some other method. This technique is used by GNU Emacs to implement
61 its "dumping" function.
62
63 Hook function pointers are never saved or restored by these functions,
64 with two exceptions: if malloc checking (see mallopt(3)) was in use
65 when malloc_get_state() was called, then malloc_set_state() resets mal‐
66 loc checking hooks if possible; if malloc checking was not in use in
67 the recorded state, but the caller has requested malloc checking, then
68 the hooks are reset to 0.
69
71 malloc(3), mallopt(3)
72
74 This page is part of release 5.07 of the Linux man-pages project. A
75 description of the project, information about reporting bugs, and the
76 latest version of this page, can be found at
77 https://www.kernel.org/doc/man-pages/.
78
79
80
81GNU 2017-09-15 MALLOC_GET_STATE(3)