1malloc_get_state(3)        Library Functions 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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

13       #include <malloc.h>
14
15       void *malloc_get_state(void);
16       int malloc_set_state(void *state);
17

DESCRIPTION

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

RETURN VALUE

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

ATTRIBUTES

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

STANDARDS

56       GNU.
57

NOTES

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

SEE ALSO

72       malloc(3), mallopt(3)
73
74
75
76Linux man-pages 6.04              2023-03-30               malloc_get_state(3)
Impressum