TLSF 2.4 released (sbrk/mmap support and more added)

TLSF Memory Storage allocator implementation.
Version 2.4 Feb 2008

New functionality added:

  • Growing the memory pool

    Starting from the version 2.4, the function add_new_area adds an
    memory area to an existing memory pool.

    - size_t add_new_area(void *, size_t, void *);

    This feature is pretty useful when an existing memory pool is running
    low and we want to add more free memory to it.

    EXAMPLE OF USE:

    char memory_pool[1024*1024];
    char memory_pool2[1024*1024];

    {
    ...

    init_memory_pool(1024*1024, memory_pool);

    ...

    ptr[0]=malloc_ex(1024*256 memory_pool);
    ptr[1]=malloc_ex(1024*512, memory_pool);
    add_new_area(memory_pool2, 1024*1024, memory_pool);
    // Now we have an extra free memory area of 1Mb
    // The next malloc may not fail
    ptr[2]=malloc_ex(1024*512, memory_pool);

    ...

    }

  • SBRK and MMAP support

    The version 2.4 can use the functions SBRK and MMAP to _automatically_
    growing the memory pool, before running out of memory.

    So, when this feature is enabled, unless the operating system were out
    of memory, a malloc operation would not fail due to an "out-of-memory"
    error.

    To enable this support, compile tlsf.c with the FLAGS -DUSE_MMAP=1 or
    -DUSE_SBRK=1 depending on whether you want to use "mmap" or "sbrk" or both.

    ** By default (default Makefile) this feature is enabled.

    EXAMPLE OF USE:

    gcc -o tlsf.o -O2 -Wall -DUSE_MMAP=1 -DUSE_SBRK=1

    ---

    If the sbrk/mmap support is enabled and we are _only_ going to use one
    memory pool, it is not necessary to call init_memory_pool

    EXAMPLE OF USE (with MMAP/SBRK support enabled):

    {
    ...

    ptr2=tlsf_malloc(100); // This function will use memory_pool

    ...

    tlsf_free(ptr2);
    }