src/cx/buffer.h

changeset 1515
f024313c08f1
parent 1514
ee5d668a71e4
equal deleted inserted replaced
1514:ee5d668a71e4 1515:f024313c08f1
437 * @retval false otherwise 437 * @retval false otherwise
438 */ 438 */
439 cx_attr_nonnull cx_attr_nodiscard 439 cx_attr_nonnull cx_attr_nodiscard
440 CX_EXPORT bool cxBufferEof(const CxBuffer *buffer); 440 CX_EXPORT bool cxBufferEof(const CxBuffer *buffer);
441 441
442 /**
443 * Ensures that the buffer has the required capacity.
444 *
445 * If the current capacity is not sufficient, the buffer will be extended.
446 *
447 * This function will reserve no more bytes than requested, in contrast to
448 * cxBufferMinimumCapacity(), which may reserve more bytes to improve the
449 * number of future necessary reallocations.
450 *
451 * @param buffer the buffer
452 * @param capacity the required capacity for this buffer
453 * @retval zero the capacity was already sufficient or successfully increased
454 * @retval non-zero on allocation failure
455 * @see cxBufferShrink()
456 * @see cxBufferMinimumCapacity()
457 */
458 cx_attr_nonnull
459 CX_EXPORT int cxBufferReserve(CxBuffer *buffer, size_t capacity);
442 460
443 /** 461 /**
444 * Ensures that the buffer has a minimum capacity. 462 * Ensures that the buffer has a minimum capacity.
445 * 463 *
446 * If the current capacity is not sufficient, the buffer will be extended. 464 * If the current capacity is not sufficient, the buffer will be generously
465 * extended.
447 * 466 *
448 * The new capacity will be a power of two until the system's page size is reached. 467 * The new capacity will be a power of two until the system's page size is reached.
449 * Then, the new capacity will be a multiple of the page size. 468 * Then, the new capacity will be a multiple of the page size.
450 * 469 *
451 * @param buffer the buffer 470 * @param buffer the buffer
452 * @param capacity the minimum required capacity for this buffer 471 * @param capacity the minimum required capacity for this buffer
453 * @retval zero the capacity was already sufficient or successfully increased 472 * @retval zero the capacity was already sufficient or successfully increased
454 * @retval non-zero on allocation failure 473 * @retval non-zero on allocation failure
474 * @see cxBufferReserve()
455 * @see cxBufferShrink() 475 * @see cxBufferShrink()
456 */ 476 */
457 cx_attr_nonnull 477 cx_attr_nonnull
458 CX_EXPORT int cxBufferMinimumCapacity(CxBuffer *buffer, size_t capacity); 478 CX_EXPORT int cxBufferMinimumCapacity(CxBuffer *buffer, size_t capacity);
459 479
469 * If the #CX_BUFFER_COPY_ON_WRITE or #CX_BUFFER_COPY_ON_EXTEND flag is set, 489 * If the #CX_BUFFER_COPY_ON_WRITE or #CX_BUFFER_COPY_ON_EXTEND flag is set,
470 * this function does nothing. 490 * this function does nothing.
471 * 491 *
472 * @param buffer the buffer 492 * @param buffer the buffer
473 * @param reserve the number of bytes that shall remain reserved 493 * @param reserve the number of bytes that shall remain reserved
494 * @see cxBufferReserve()
474 * @see cxBufferMinimumCapacity() 495 * @see cxBufferMinimumCapacity()
475 */ 496 */
476 cx_attr_nonnull 497 cx_attr_nonnull
477 CX_EXPORT void cxBufferShrink(CxBuffer *buffer, size_t reserve); 498 CX_EXPORT void cxBufferShrink(CxBuffer *buffer, size_t reserve);
478 499

mercurial