33 void* a = arena.
alloc(5);
44 void* a = arena.
alloc(0);
45 void* b = arena.
alloc(0);
46 void* c = arena.
alloc(0);
55 vector<pair<char*, char*> > allocs;
57 for (
size_t i = 3; i < 10; ++i) {
58 for (
size_t size = 0; size < 100; ++size) {
59 char* a =
static_cast<char*
>(arena.
alloc(size));
60 pair<char*, char*> p(a, a + size);
61 for (
size_t j = 0; j < allocs.size(); ++j) {
62 pair<char*, char*> p2 = allocs[j];
63 if (p.first <= p2.first)
68 fill(p.first, p.second,
static_cast<char>(-1));
72 while (allocs.size() > 10 * i) {
73 arena.
freeTop(allocs.back().first);
98 const size_t smallerOverflow = 1ul << (8*
sizeof(long) - 1);
99 ASSERT(smallerOverflow > 0);
100 ASSERT(smallerOverflow *
sizeof(
long) == 0);
104 const size_t greaterOverflow = (~(0ul)) >> 1;
105 ASSERT(
sizeof(
long) >= 4);
106 ASSERT(greaterOverflow *
sizeof(
long) > greaterOverflow);
107 ASSERT(greaterOverflow != (greaterOverflow *
sizeof(
long)) /
sizeof(
long));
114 template<
class T,
size_t ThrowAt>
115 class _frobby_Helper {
119 if (_id == ThrowAt) {
130 void setId(
size_t id) {_id = id;}
132 static string getLog() {
return _log.str();}
136 static size_t _count;
137 static ostringstream _log;
140 template<
class T,
size_t ThrowAt>
141 size_t _frobby_Helper<T, ThrowAt>::_count = 0;
143 template<
class T,
size_t ThrowAt>
144 ostringstream _frobby_Helper<T, ThrowAt>::_log;
146 #define MAKE_HELPER(NAME, THROW_AT) \
148 struct _frobby_##NAME##HelperTag {}; \
149 typedef _frobby_Helper<_frobby_##NAME##HelperTag, THROW_AT> NAME##Helper; \
158 ASSERT_EQ(ConDeconHelper::getLog(),
"+1+2+3-3-2-1");
166 ASSERT_EQ(ConExcepHelper::getLog(),
"+1+2+3T4-3-2-1");
173 pair<NoConDeconHelper*, NoConDeconHelper*> p =
180 ASSERT_EQ(NoConDeconHelper::getLog(),
"-3-2-1");
188 ASSERT_EQ(ConNoDeconHelper::getLog(),
"+1+2+3");
#define MAKE_HELPER(NAME, THROW_AT)
#define ASSERT_EXCEPTION(CODE, EXCEPTION_TYPE)
#define ASSERT_TRUE(VALUE)
#define ASSERT_FALSE_SILENT(VALUE)
#define ASSERT_FALSE(VALUE)
This is an arena allocator.
void * alloc(size_t size)
Returns a pointer to a buffer of size bytes.
bool isEmpty() const
Returns true if there are no live allocations for this Arena.
pair< T *, T * > allocArrayNoCon(size_t elementCount)
As alloc(elementCount * sizeof(T)).
void freeTop(void *ptr)
Frees the buffer pointed to by ptr.
void freeTopArray(T *array, T *arrayEnd)
As freeTop(array) except that the elements of the array in the range (array, arrayEnd] are deconstruc...
void freeAndAllAfter(void *ptr)
Frees the buffer pointed to by ptr and all not yet freed allocations that have happened since that bu...
pair< T *, T * > allocArray(size_t elementCount)
As allocArrayNoCon except that constructors for the elements of the array are called.
#define TEST_SUITE(SUITE)