ArrayTable prevent block overflow
This commit is contained in:
parent
b57fcf173e
commit
ab2b1924e8
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "Vector.hh"
|
||||
#include "ObjectId.hh"
|
||||
#include "Error.hh"
|
||||
|
||||
namespace sta {
|
||||
|
||||
|
|
@ -42,8 +43,9 @@ public:
|
|||
size_t size() const { return size_; }
|
||||
void clear();
|
||||
|
||||
static constexpr ObjectId idx_bits = 10;
|
||||
static constexpr ObjectId block_size = (1 << idx_bits);
|
||||
static constexpr int idx_bits = 7;
|
||||
static constexpr int block_size = (1 << idx_bits);
|
||||
static constexpr int block_id_max = 1 << (object_id_bits - idx_bits);
|
||||
|
||||
private:
|
||||
ArrayBlock<TYPE> *makeBlock(uint32_t size);
|
||||
|
|
@ -129,6 +131,8 @@ void
|
|||
ArrayTable<TYPE>::pushBlock(ArrayBlock<TYPE> *block)
|
||||
{
|
||||
blocks_[blocks_size_++] = block;
|
||||
if (blocks_size_ >= block_id_max)
|
||||
internalError("max array table block count exceeded.");
|
||||
if (blocks_size_ == blocks_capacity_) {
|
||||
size_t new_capacity = blocks_capacity_ * 1.5;
|
||||
ArrayBlock<TYPE>** new_blocks = new ArrayBlock<TYPE>*[new_capacity];
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ typedef uint32_t BlockIdx;
|
|||
// Object index within a block.
|
||||
typedef uint32_t ObjectIdx;
|
||||
|
||||
static constexpr int object_id_bits = sizeof(ObjectId) * 8;
|
||||
static constexpr BlockIdx block_idx_null = 0;
|
||||
static constexpr ObjectId object_id_null = 0;
|
||||
static constexpr ObjectIdx object_idx_null = 0;
|
||||
|
|
|
|||
|
|
@ -43,8 +43,9 @@ public:
|
|||
void clear();
|
||||
|
||||
// Objects are allocated in blocks of 128.
|
||||
static constexpr ObjectId idx_bits = 7;
|
||||
static constexpr ObjectId block_object_count = (1 << idx_bits);
|
||||
static constexpr int idx_bits = 7;
|
||||
static constexpr int block_object_count = (1 << idx_bits);
|
||||
static constexpr int block_id_max = 1 << (object_id_bits - idx_bits);
|
||||
|
||||
private:
|
||||
void makeBlock();
|
||||
|
|
@ -104,6 +105,8 @@ ObjectTable<TYPE>::makeBlock()
|
|||
BlockIdx block_index = blocks_.size();
|
||||
TableBlock<TYPE> *block = new TableBlock<TYPE>(block_index, this);
|
||||
blocks_.push_back(block);
|
||||
if (blocks_.size() >= block_id_max)
|
||||
internalError("max object table block count exceeded.");
|
||||
// ObjectId zero is reserved for object_id_null.
|
||||
int last = (block_index > 0) ? 0 : 1;
|
||||
for (int i = block_object_count - 1; i >= last; i--) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue