Class allocator_malloc

Synopsis

#include <include/EASTL/allocator_malloc.h>

class allocator_malloc

Description

allocator_malloc

Implements an EASTL allocator that uses malloc/free as opposed to new/delete or PPMalloc Malloc/Free.

Example usage: vector<int, allocator_malloc> intVector;

Methods

allocator_malloc overload
allocate overload
deallocate
get_name
operator!=
operator=
operator==
set_name

Source

Lines 70-114 in include/EASTL/allocator_malloc.h.

class allocator_malloc
{
public:
    allocator_malloc(const char* = NULL)
        { }
    allocator_malloc(const allocator_malloc&)
        { }
    allocator_malloc(const allocator_malloc&, const char*)
        { }
    allocator_malloc& operator=(const allocator_malloc&)
        { return *this; }
    bool operator==(const allocator_malloc&)
        { return true; }
    bool operator!=(const allocator_malloc&)
        { return false; }
    void* allocate(size_t n, int /*flags*/ = 0)
        { return malloc(n); }
    void* allocate(size_t n, size_t alignment, size_t alignmentOffset, int /*flags*/ = 0)
    { 
        #if EASTL_ALIGNED_MALLOC_AVAILABLE
            if((alignmentOffset % alignment) == 0) // We check for (offset % alignmnent == 0) instead of (offset == 0) because any block which is aligned on e.g. 64 also is aligned at an offset of 64 by definition. 
                return memalign(alignment, n); // memalign is more consistently available than posix_memalign.
        #else
            if((alignment <= EASTL_SYSTEM_ALLOCATOR_MIN_ALIGNMENT) && ((alignmentOffset % alignment) == 0))
                return malloc(n);
        #endif
        return NULL;
    }
    void deallocate(void* p, size_t /*n*/)
        { free(p); }
    const char* get_name() const
        { return "allocator_malloc"; }
    void set_name(const char*)
        { }
};





Add Discussion as Guest

Log in