/// Precondition: this->unique() /// WARNING: Use with extreme care. void unique_push_back(T const& v) { passert(this->unique(), "Vector is not unique"); if (full()) realloc_((size() + 1) * 3 / 2); *end_ = v; ++end_; }
T* space1_() { if(!this->unique() || end_ == limit_) { // Make unique realloc_((size() + 1) * 3 / 2); } T* ret = end_; ++end_; return ret; }
T* space_(size_type amount) { if(!this->unique() || size() + amount >= capacity()) { // Make unique realloc_((size() + amount) * 3 / 2); } T* ret = end_; end_ += amount; return ret; }
void* realloc(void* ptr, size_t size) { if (!ptr) return malloc(size); if (!size) { free(ptr); return NULL; } void* ret=realloc_(ptr, size); if (!ret) abort(); if (ignore==0) { ignore++; cb.realloc(ptr, ret, size); ignore--; } return ret; }
/*---------------------------------------------------------------------------* * NAME: push_data(config *conf, unsigned char *ptr, unsigned int size) * DESC: push data to the pkt buffer using realloc *---------------------------------------------------------------------------*/ void push_data(config *conf, unsigned char *ptr, unsigned int size) { /* debug */ debug(1, "<-----------------------[enter]\n"); /* realloc the buffer */ conf->buf_fuzz = (unsigned char *) realloc_(conf->buf_fuzz, conf->buf_fuzz_size + size); /* copy the data */ memcpy(conf->buf_fuzz + conf->buf_fuzz_size, ptr, size); /* update the size */ conf->buf_fuzz_size+=size; /* update the size of the blocks */ update_block_size(conf, size); /* debug */ debug(1, "<-----------------------[quit]\n"); }
/// Returned pointer is only valid until any other non-const member function /// is called. NOTE: Returned pointer can also be invalidated if this /// vector refers to some transient storage that is destroyed. T* mut_data() { if(!this->unique()) realloc_(size()); return begin_; }
/// NOTE: Invalidates iterators to this object /// Precondition: not heap allocated void heap_allocate() { passert(!data_, "Already heap allocated"); realloc_(size()); }
void reserve(size_type n) { if(capacity() < n) realloc_(n); }