PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ bytebuffer_makeroom()

static void bytebuffer_makeroom ( bytebuffer_t s,
size_t  size_to_add 
)
inlinestatic

If necessary, expand the bytebuffer_t internal buffer to accomodate the specified additional size.

Definition at line 140 of file bytebuffer.c.

References bytebuffer_t::buf_start, bytebuffer_t::buf_static, bytebuffer_t::capacity, lwalloc(), LWDEBUGF, lwrealloc(), bytebuffer_t::readcursor, and bytebuffer_t::writecursor.

Referenced by bytebuffer_append_bulk(), bytebuffer_append_byte(), bytebuffer_append_bytebuffer(), bytebuffer_append_double(), bytebuffer_append_int(), bytebuffer_append_uvarint(), and bytebuffer_append_varint().

141 {
142  LWDEBUGF(2,"Entered bytebuffer_makeroom with space need of %d", size_to_add);
143  size_t current_write_size = (s->writecursor - s->buf_start);
144  size_t current_read_size = (s->readcursor - s->buf_start);
145  size_t capacity = s->capacity;
146  size_t required_size = current_write_size + size_to_add;
147 
148  LWDEBUGF(2,"capacity = %d and required size = %d",capacity ,required_size);
149  while (capacity < required_size)
150  capacity *= 2;
151 
152  if ( capacity > s->capacity )
153  {
154  LWDEBUGF(4,"We need to realloc more memory. New capacity is %d", capacity);
155  if ( s->buf_start == s->buf_static )
156  {
157  s->buf_start = lwalloc(capacity);
158  memcpy(s->buf_start, s->buf_static, s->capacity);
159  }
160  else
161  {
162  s->buf_start = lwrealloc(s->buf_start, capacity);
163  }
164  s->capacity = capacity;
165  s->writecursor = s->buf_start + current_write_size;
166  s->readcursor = s->buf_start + current_read_size;
167  }
168  return;
169 }
uint8_t buf_static[BYTEBUFFER_STATICSIZE]
Definition: bytebuffer.h:44
uint8_t * writecursor
Definition: bytebuffer.h:42
uint8_t * readcursor
Definition: bytebuffer.h:43
size_t capacity
Definition: bytebuffer.h:40
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:237
uint8_t * buf_start
Definition: bytebuffer.h:41
void * lwalloc(size_t size)
Definition: lwutil.c:229
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
Here is the call graph for this function:
Here is the caller graph for this function: