| 245 | } |
| 246 | |
| 247 | bool MemPool::CheckIntegrity(bool check_current_chunk_empty) { |
| 248 | DCHECK_EQ(zero_length_region_, MEM_POOL_POISON); |
| 249 | DCHECK_LT(current_chunk_idx_, static_cast<int>(chunks_.size())); |
| 250 | |
| 251 | // check that current_chunk_idx_ points to the last chunk with allocated data |
| 252 | int64_t total_allocated = 0; |
| 253 | int64_t total_reserved = 0; |
| 254 | for (int i = 0; i < chunks_.size(); ++i) { |
| 255 | DCHECK_GT(chunks_[i].size, 0); |
| 256 | total_reserved += chunks_[i].size; |
| 257 | if (i < current_chunk_idx_) { |
| 258 | DCHECK_GT(chunks_[i].allocated_bytes, 0); |
| 259 | } else if (i == current_chunk_idx_) { |
| 260 | DCHECK_GE(chunks_[i].allocated_bytes, 0); |
| 261 | if (check_current_chunk_empty) DCHECK_EQ(chunks_[i].allocated_bytes, 0); |
| 262 | } else { |
| 263 | DCHECK_EQ(chunks_[i].allocated_bytes, 0); |
| 264 | } |
| 265 | total_allocated += chunks_[i].allocated_bytes; |
| 266 | } |
| 267 | DCHECK_EQ(total_allocated, total_allocated_bytes_); |
| 268 | DCHECK_EQ(total_reserved, total_reserved_bytes_); |
| 269 | return true; |
| 270 | } |