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