Bool DynBuf_Trim(DynBuf *b) // IN/OUT: { ASSERT(b); return DynBufRealloc(b, b->size); }
Bool DynBuf_Enlarge(DynBuf *b, // IN/OUT: size_t minSize) // IN: { size_t newAllocated; ASSERT(b); newAllocated = b->allocated ? #if defined(DYNBUF_DEBUG) b->allocated + 1 #else /* * Double the previously allocated size if it is less * than 256KB; otherwise grow it linearly by 256KB */ (b->allocated < 256 * 1024 ? b->allocated * 2 : b->allocated + 256 * 1024) #endif : #if defined(DYNBUF_DEBUG) 1 #else /* * Initial size: 1 KB. Most buffers are smaller than * that --hpreg */ 1 << 10 #endif ; if (minSize > newAllocated) { newAllocated = minSize; } /* * Prevent integer overflow. We can use this form of checking specifically * because a multiple by 2 is used (in the worst case). This type of * checking does not work in the general case. */ if (newAllocated < b->allocated) { return FALSE; } return DynBufRealloc(b, newAllocated); }
Bool DynBuf_Enlarge(DynBuf *b, // IN size_t min_size) // IN { size_t new_allocated; ASSERT(b); new_allocated = b->allocated ? #if defined(DYNBUF_DEBUG) b->allocated + 1 #else /* * Double the previously allocated size if it is less * than 256KB; otherwise grow it linearly by 256KB */ (b->allocated < 256 * 1024 ? b->allocated * 2 : b->allocated + 256 * 1024) #endif : #if defined(DYNBUF_DEBUG) 1 #else /* * Initial size: 1 KB. Most buffers are smaller than * that --hpreg */ 1 << 10 #endif ; if (min_size > new_allocated) { new_allocated = min_size; } return DynBufRealloc(b, new_allocated); }