3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-12 06:00:53 +00:00
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2018-11-21 13:48:48 -08:00
parent 8590876d18
commit 0c1408b30e
5 changed files with 88 additions and 43 deletions

View file

@ -31,6 +31,7 @@ Revision History:
#include "util/memory_manager.h"
#include "util/debug.h"
#include "util/trace.h"
#include "util/tptr.h"
#ifdef Z3DEBUG
#include "util/hashtable.h"
#endif
@ -54,8 +55,9 @@ protected:
cell * m_next;
T m_data;
cell():m_next(reinterpret_cast<cell*>(1)) {}
bool is_free() const { return m_next == reinterpret_cast<cell*>(1); }
void mark_free() { m_next = reinterpret_cast<cell*>(1); }
bool is_free() const { return GET_TAG(m_next) == 1; }
void mark_free() { m_next = TAG(cell*, m_next, 1); }
void unmark_free() { m_next = UNTAG(cell*, m_next); }
};
cell * m_table; // array of cells.
@ -70,6 +72,7 @@ protected:
#endif
cell * m_next_cell;
cell * m_free_cell;
cell * m_tofree_cell;
unsigned get_hash(T const & d) const { return HashProc::operator()(d); }
bool equals(T const & e1, T const & e2) const { return EqProc::operator()(e1, e2); }
@ -171,6 +174,7 @@ protected:
m_slots = new_slots;
m_next_cell = next_cell;
m_free_cell = nullptr;
m_tofree_cell = nullptr;
CASSERT("chashtable", check_invariant());
return;
}
@ -204,6 +208,12 @@ protected:
m_free_cell = c;
}
void push_recycle_cell(cell* c) {
SASSERT(c < m_table + m_capacity);
c->m_next = m_tofree_cell;
m_tofree_cell = c;
}
void init(unsigned slots, unsigned cellar) {
m_capacity = slots + cellar;
m_table = alloc_table(m_capacity);
@ -212,6 +222,7 @@ protected:
m_size = 0;
m_next_cell = m_table + slots;
m_free_cell = nullptr;
m_tofree_cell = nullptr;
}
public:

View file

@ -292,8 +292,10 @@ void memory::deallocate(void * p) {
void * memory::allocate(size_t s) {
s = s + sizeof(size_t); // we allocate an extra field!
void * r = malloc(s);
if (r == 0)
if (r == 0) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
g_memory_thread_alloc_size += s;
g_memory_thread_alloc_count += 1;
@ -317,8 +319,10 @@ void* memory::reallocate(void *p, size_t s) {
}
void *r = realloc(real_p, s);
if (r == 0)
if (r == 0) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
}
@ -361,8 +365,10 @@ void * memory::allocate(size_t s) {
if (counts_exceeded)
throw_alloc_counts_exceeded();
void * r = malloc(s);
if (r == nullptr)
if (r == nullptr) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
}
@ -389,8 +395,10 @@ void* memory::reallocate(void *p, size_t s) {
if (counts_exceeded)
throw_alloc_counts_exceeded();
void *r = realloc(real_p, s);
if (r == nullptr)
if (r == nullptr) {
throw_out_of_memory();
return nullptr;
}
*(static_cast<size_t*>(r)) = s;
return static_cast<size_t*>(r) + 1; // we return a pointer to the location after the extra field
}