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 <stdlib.h>
11
12       void* malloc_get_state(void);
13
14       int malloc_set_state(void *state);
15

DESCRIPTION

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

RETURN VALUE

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

CONFORMING TO

42       These functions are GNU extensions.
43

NOTES

45       These  functions are especially useful when using this malloc(3) imple‐
46       mentation as part of a  shared  library,  and  the  heap  contents  are
47       saved/restored  via  some  other method.  This technique is used by the
48       GNU Emacs to implement its "dumping" function.
49
50       Hook function pointers are never saved or restored by these  functions,
51       with  two  exceptions:  if  malloc checking (see mallopt(3)) was in use
52       when malloc_get_state() was called, then malloc_set_state() resets mal‐
53       loc  checking  hooks  if possible; if malloc checking was not in use in
54       the recorded state, but the caller has requested malloc checking,  then
55       the hooks are reset to 0.
56

SEE ALSO

58       malloc(3), mallopt(3)
59

COLOPHON

61       This  page  is  part of release 3.53 of the Linux man-pages project.  A
62       description of the project, and information about reporting  bugs,  can
63       be found at http://www.kernel.org/doc/man-pages/.
64
65
66
67GNU                               2012-05-04               MALLOC_GET_STATE(3)
Impressum