1MALLOC_GET_STATE(3)        Linux Programmer's Manual       MALLOC_GET_STATE(3)
2
3
4

NAME

6       malloc_get_state, malloc_set_state - record and restore state of malloc
7       implementation
8

SYNOPSIS

10       #include <malloc.h>
11
12       void *malloc_get_state(void);
13       int malloc_set_state(void *state);
14

DESCRIPTION

16       Note: these function are removed in glibc version 2.25.
17
18       The malloc_get_state() function records the current state of  all  mal‐
19       loc(3)  internal  bookkeeping variables (but not the actual contents of
20       the heap or the state of malloc_hook(3) functions pointers).  The state
21       is recorded in a system-dependent opaque data structure dynamically al‐
22       located via malloc(3), and a pointer to that data structure is returned
23       as  the function result.  (It is the caller's responsibility to free(3)
24       this memory.)
25
26       The malloc_set_state() function restores the state of all malloc(3) in‐
27       ternal  bookkeeping variables to the values recorded in the opaque data
28       structure pointed to by state.
29

RETURN VALUE

31       On success, malloc_get_state() returns a pointer to a  newly  allocated
32       opaque  data structure.  On error (for example, memory could not be al‐
33       located for the data structure), malloc_get_state() returns NULL.
34
35       On success, malloc_set_state() returns 0.  If  the  implementation  de‐
36       tects  that  state does not point to a correctly formed data structure,
37       malloc_set_state() returns -1.  If the implementation detects that  the
38       version  of  the  data  structure referred to by state is a more recent
39       version than this implementation knows  about,  malloc_set_state()  re‐
40       turns -2.
41

ATTRIBUTES

43       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
44       tributes(7).
45
46       ┌────────────────────────────────────────────┬───────────────┬─────────┐
47Interface                                   Attribute     Value   
48       ├────────────────────────────────────────────┼───────────────┼─────────┤
49malloc_get_state(), malloc_set_state()      │ Thread safety │ MT-Safe │
50       └────────────────────────────────────────────┴───────────────┴─────────┘
51

CONFORMING TO

53       These functions are GNU extensions.
54

NOTES

56       These functions are useful when using this malloc(3) implementation  as
57       part  of a shared library, and the heap contents are saved/restored via
58       some other method.  This technique is used by GNU  Emacs  to  implement
59       its "dumping" function.
60
61       Hook  function pointers are never saved or restored by these functions,
62       with two exceptions: if malloc checking (see  mallopt(3))  was  in  use
63       when malloc_get_state() was called, then malloc_set_state() resets mal‐
64       loc checking hooks if possible; if malloc checking was not  in  use  in
65       the  recorded state, but the caller has requested malloc checking, then
66       the hooks are reset to 0.
67

SEE ALSO

69       malloc(3), mallopt(3)
70

COLOPHON

72       This page is part of release 5.13 of the Linux  man-pages  project.   A
73       description  of  the project, information about reporting bugs, and the
74       latest    version    of    this    page,    can     be     found     at
75       https://www.kernel.org/doc/man-pages/.
76
77
78
79GNU                               2021-03-22               MALLOC_GET_STATE(3)
Impressum