Giter Site home page Giter Site logo

pmalloc's Introduction

A portable persistent memory allocation library.

Features:

  • Optimized memory layout arrangement
  • persistent key-value pair storage (fixed length)
  • portable address support
  • in-place structured data persistence

How to use it ?

setup a memory descriptor for persistent memory pool

    /* attache to a file hander */
    void *md = pmalloc_attach(fd, NULL, PM_CAPACITY);
    /* capture error */
    assert(NULL != md);
    ....
    /* close it */
    pmalloc_detach(md);

manipulate persistent memory blocks

    for (i = 0; i < 16; ++i)
    {
        /* fetch persistent key values */
        key = pmalloc_getkey(md, i);
        if (NULL != key)
            printf("Prekey... %p --> %s %lu\n", key, (char*)key, sizeof(size_t));
        else break;
    }
    ...
    /* allocate a memory block with specified size */
    void *data = pmalloc(md, 0x1000 * 5);
    if (NULL != data) {
        sprintf(data, "output data row %d", i);
        /* put it on key-value pair store */
        pmalloc_setkey(md, i, data);
    }
    ...
    /* retrieve a persisted memory block from key-value pair store with a specified key */
    keydata = pmalloc_getkey(md, keyidx);
    if (NULL != keydata) {
        /* free up an allocated block
        pmfree(md, keydata);
        pmalloc_setkey(md, keyidx, NULL);
        printf(ANSI_COLOR_GREEN "Released original key data at %p! \n" ANSI_COLOR_RESET, keydata);
    } else 
        printf(ANSI_COLOR_CYAN "No original key data set in this key slot! \n" ANSI_COLOR_RESET);

How to Build it ?

Please install the following check module first for unit test compiling.
http://libcheck.github.io/check/web/install.html
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

How to package it ?

$ cd build
$ cpack -C CPackConfig.cmake

pmalloc's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.