Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default persistent malloc

    I'm looking for a malloc replacement that uses a persistent mmap'd file, so
    that malloced data structures persist from one run to the other. I've tried
    mmalloc, which comes with gdb, and it works mostly but I get some core dumps,
    which don't happen when I use malloc from libc.

    Does anyone have experience with mmalloc and persistency?
    Is there a simpler or better alternative?

    Thanks for any info.
    Luiz Henrique de Figueiredo Guest

  2. Similar Questions and Discussions

    1. Persistent Shared Object not being persistent
      hi my fms app maintains a persistent shared object to keep track of daily highscores, however whenever the app is reloaded or restarted all the...
    2. /usr/include/malloc.h:3:2: #error "<malloc.h> has been replaced by <stdlib.h>" Error code 1
      Hi, if I try to build the tac_plus-4.4beta2 Tacacs Server from http://www.networkforums.net/ on my FreeBSD 5.3-RELEASE-p5 I get this Error message...
    3. [PHP-DEV] [PATCH] __attribute_malloc__ for malloc-like functions
      > I expect the effect to be significant, though, because (as I pointed attribute((malloc)) is now enabled in CVS. Note that erealloc was...
    4. [PHP-DEV] [PATCH] __attribute_malloc__ for malloc-like functions
      > account that every pointer in scope might be an alias of the resulting What about erealloc? It can return the same pointer as passed to it. ...
    5. CLI stored procedure and malloc
      Hi, I'm writting a stored procedure with several mallocs in it. The first ones work fine but after a point, doing a malloc makes the procedure...
  3. #2

    Default Re: persistent malloc


    "Luiz Henrique de Figueiredo" <lhf@csgpwr1.uwaterloo.ca> wrote in message
    news:bg763e$pum$1@tabloid.uwaterloo.ca...
    > I'm looking for a malloc replacement that uses a persistent mmap'd file,
    so
    > that malloced data structures persist from one run to the other.
    I don't follow. Can you be more precise about what you're trying to do.
    > Does anyone have experience with mmalloc and persistency?
    > Is there a simpler or better alternative?
    Decide on what data you want to save across runs, decide on a format for
    that data, and write it to a file. If you're using C++, store the data you
    need in serializable classes.

    DS


    David Schwartz Guest

  4. #3

    Default Re: persistent malloc

    In article <bg78m7$26f$1@nntp.webmaster.com>,
    David Schwartz <davids@webmaster.com> wrote:
    >
    > I don't follow. Can you be more precise about what you're trying to do.
    I want all my malloc'd data to be saved into a file, pointers and all, and I
    want to be able to load the file in each run and get the same data structures,
    pointers and all, as in the previous run. I don't want serialization. I want
    to lazy route. :-)

    The mmalloc library that comes with gdb provides a malloc replacement that
    uses a mmap'd file as its pool. The file persists across runs and does what I
    want, expect that I get some seg faults that I don't get when using the
    default malloc from the C library.

    For infor on mmalloc, see [url]http://sources.redhat.com/gdb/onlinedocs/mmalloc.html[/url]

    So, does anyone have experience using mmalloc for this?

    Thanks.
    Luiz Henrique de Figueiredo Guest

  5. #4

    Default Re: persistent malloc


    "Luiz Henrique de Figueiredo" <lhf@csgpwr1.uwaterloo.ca> wrote in message
    news:bg79je$rtb$1@tabloid.uwaterloo.ca...
    > In article <bg78m7$26f$1@nntp.webmaster.com>,
    > David Schwartz <davids@webmaster.com> wrote:
    > > I don't follow. Can you be more precise about what you're trying to
    do.
    > I want all my malloc'd data to be saved into a file, pointers and all, and
    I
    > want to be able to load the file in each run and get the same data
    structures,
    > pointers and all, as in the previous run. I don't want serialization. I
    want
    > to lazy route. :-)
    That's not really possible in principle. What if the address one of
    those pointers points to is already in use at the time your process attempts
    to attach to the file?
    > The mmalloc library that comes with gdb provides a malloc replacement that
    > uses a mmap'd file as its pool. The file persists across runs and does
    what I
    > want, expect that I get some seg faults that I don't get when using the
    > default malloc from the C library.
    I'm not surprised you get segfaults. The pointers probably don't point
    to the right place in the new process.

    You can make this work, but all of your pointers must be relative to the
    base of the file. There are other requirements as well.

    DS


    David Schwartz Guest

  6. #5

    Default Re: persistent malloc

    > That's not really possible in principle. What if the address one of
    > those pointers points to is already in use at the time your process attempts
    > to attach to the file?
    >
    >
    >>The mmalloc library that comes with gdb provides a malloc replacement that
    >>uses a mmap'd file as its pool. The file persists across runs and does
    >
    > what I
    >
    >>want, expect that I get some seg faults that I don't get when using the
    >>default malloc from the C library.
    >
    >
    > I'm not surprised you get segfaults. The pointers probably don't point
    > to the right place in the new process.
    >
    > You can make this work, but all of your pointers must be relative to the
    > base of the file. There are other requirements as well.
    >

    I wrote a malloc (also called MMmalloc) that has a mode were all the
    pointers in the arena are offsets and can be mmapped anywhere in the
    process space.

    I've placed it here:

    [url]http://www.mariani.ws/~gianni/MMmalloc.tar.gz[/url]

    It's way old but it's easy enough to extract the interesting bits (being
    how to create a relocatable arena).

    G

    Gianni Mariani Guest

  7. #6

    Default Re: persistent malloc

    On Wed, 30 Jul 2003 02:13:02 +0000, Luiz Henrique de Figueiredo wrote:
    > In article <bg78m7$26f$1@nntp.webmaster.com>,
    > David Schwartz <davids@webmaster.com> wrote:
    >>
    >> I don't follow. Can you be more precise about what you're trying to do.
    >
    > I want all my malloc'd data to be saved into a file, pointers and all, and I
    > want to be able to load the file in each run and get the same data structures,
    > pointers and all, as in the previous run. I don't want serialization. I want
    > to lazy route. :-)
    The problem here is global variables, say you have...

    static struct store *beg = NULL;

    static struct store *store_add(void *data);
    static void store_del(struct store *store);
    static struct store *store_srch(void *data);

    Now everything inside the store_* API should be fine, assuming you can
    easily restore the memory via. MAP_FIXED etc. However the "beg" variable
    isn't known the the malloc() calls, so you need to register all
    static/global variables so you can restore them (I've seen this done and
    it's _far_ from the lazy route) ... As a corner case of this you could
    probably use a single global and have everything else use a context that
    is passed to them, but this is only feasable if almost everything already
    takes a context.

    Also note that in both cases you can never call anything like
    gethostbyname() etc. unless you're malloc replacement has different
    function names than malloc() and free().

    --
    James Antill -- [email]james@and.org[/email]
    Need an efficent and powerful string library for C?
    [url]http://www.and.org/vstr/[/url]

    James Antill Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139