Class CrtAllocator

Synopsis

#include <include/rapidjson/allocators.h>

class CrtAllocator

Description

C-runtime library allocator.

This class is just wrapper for standard C library memory routines.

Note
implements Allocator concept

Mentioned in

Methods

Free
Malloc
operator!=
operator==
Realloc

Source

Lines 82-107 in include/rapidjson/allocators.h.

class CrtAllocator {
public:
    static const bool kNeedFree = true;
    void* Malloc(size_t size) { 
        if (size) //  behavior of malloc(0) is implementation defined.
            return RAPIDJSON_MALLOC(size);
        else
            return NULL; // standardize to returning NULL.
    }
    void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {
        (void)originalSize;
        if (newSize == 0) {
            RAPIDJSON_FREE(originalPtr);
            return NULL;
        }
        return RAPIDJSON_REALLOC(originalPtr, newSize);
    }
    static void Free(void *ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); }

    bool operator==(const CrtAllocator&) const RAPIDJSON_NOEXCEPT {
        return true;
    }
    bool operator!=(const CrtAllocator&) const RAPIDJSON_NOEXCEPT {
        return false;
    }
};





Add Discussion as Guest

Log in