src/AllocatorPolicies.h
author David Anderson <dvander@alliedmods.net>
Sun Jan 27 17:34:30 2013 -0800 (2013-01-27)
changeset 261 219b49bf4a03
parent 86 32ad0523b309
permissions -rw-r--r--
Add support for importing enum types and enum values (as constexprs).
     1 /*
     2  * Copyright (C) 2012 David Anderson
     3  *
     4  * This file is part of JITCraft.
     5  *
     6  * JITCraft is free software: you can redistribute it and/or modify it under
     7  * the terms of the GNU General Public License as published by the Free
     8  * Software Foundation, either version 3 of the License, or (at your option)
     9  * any later version.
    10  * 
    11  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    14  *
    15  * You should have received a copy of the GNU General Public License along with
    16  * JITCraft. If not, see http://www.gnu.org/licenses/.
    17  */
    18 #ifndef _include_jc_allocators_h_
    19 #define _include_jc_allocators_h_
    20 
    21 #include <stdlib.h>
    22 
    23 namespace ke {
    24 
    25 class ZoneAllocatorPolicy
    26 {
    27   protected:
    28     void reportOutOfMemory();
    29     void reportAllocationOverflow();
    30 
    31   public:
    32     void free(void *memory) {
    33         ::free(memory);
    34     }
    35     void *malloc(size_t bytes) {
    36         void *ptr = ::malloc(bytes);
    37         if (!ptr)
    38             reportOutOfMemory();
    39         return ptr;
    40     }
    41 };
    42 
    43 }
    44 
    45 #endif // _include_jc_allocators_h_