blob: 4f7753d476169cb1253611671eb62164ebe82a1f [file] [log] [blame]
Brian Carlstrom413e89f2013-10-21 23:53:49 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "allocator.h"
18
19#include <inttypes.h>
20#include <stdlib.h>
21
22#include "base/logging.h"
23
24namespace art {
25
26class MallocAllocator : public Allocator {
27 public:
28 explicit MallocAllocator() {}
29 ~MallocAllocator() {}
30
31 virtual void* Alloc(size_t size) {
32 return calloc(sizeof(uint8_t), size);
33 }
34
35 virtual void Free(void* p) {
36 free(p);
37 }
38
39 private:
40 DISALLOW_COPY_AND_ASSIGN(MallocAllocator);
41};
42
43MallocAllocator g_malloc_allocator;
44
45class NoopAllocator : public Allocator {
46 public:
47 explicit NoopAllocator() {}
48 ~NoopAllocator() {}
49
50 virtual void* Alloc(size_t size) {
51 LOG(FATAL) << "NoopAllocator::Alloc should not be called";
52 return NULL;
53 }
54
55 virtual void Free(void* p) {
56 // Noop.
57 }
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(NoopAllocator);
61};
62
63NoopAllocator g_noop_allocator;
64
65Allocator* Allocator::GetMallocAllocator() {
66 return &g_malloc_allocator;
67}
68
69Allocator* Allocator::GetNoopAllocator() {
70 return &g_noop_allocator;
71}
72
73
74} // namespace art