| 1 |
// -*- C++ -*- |
| 2 |
|
| 3 |
/* |
| 4 |
|
| 5 |
Heap Layers: An Extensible Memory Allocation Infrastructure |
| 6 |
|
| 7 |
Copyright (C) 2000-2020 by Emery Berger |
| 8 |
http://www.emeryberger.com |
| 9 |
[email protected] |
| 10 |
|
| 11 |
Heap Layers is distributed under the terms of the Apache 2.0 license. |
| 12 |
|
| 13 |
You may obtain a copy of the License at |
| 14 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
|
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef HL_LEAMALLOCHEAP_H |
| 19 |
#define HL_LEAMALLOCHEAP_H |
| 20 |
|
| 21 |
#include <cstdlib> |
| 22 |
|
| 23 |
#include "wrappers/mallocinfo.h" |
| 24 |
|
| 25 |
/** |
| 26 |
* @class LeaMallocHeap |
| 27 |
* @brief A "source heap" that uses the Lea allocator. |
| 28 |
*/ |
| 29 |
|
| 30 |
extern "C" void * dlmalloc (size_t); |
| 31 |
extern "C" void dlfree (void *); |
| 32 |
extern "C" size_t dlmalloc_usable_size (void *); |
| 33 |
|
| 34 |
namespace HL { |
| 35 |
|
| 36 |
class LeaMallocHeap { |
| 37 |
public: |
| 38 |
enum { Alignment = MallocInfo::Alignment }; |
| 39 |
|
| 40 |
inline void * malloc (size_t sz) { |
| 41 |
void * ptr = dlmalloc (sz); |
| 42 |
return ptr; |
| 43 |
} |
| 44 |
|
| 45 |
inline void free (void * p) { |
| 46 |
dlfree (p); |
| 47 |
} |
| 48 |
|
| 49 |
inline size_t getSize (const void * p) { |
| 50 |
return dlmalloc_usable_size ((void *) p); |
| 51 |
} |
| 52 |
}; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
#endif |