src/cx/buffer.h

changeset 501
9a08f5e515cc
parent 500
eb9e7bd40a8e
child 529
814d51173f20
     1.1 --- a/src/cx/buffer.h	Sun Jan 30 14:19:00 2022 +0100
     1.2 +++ b/src/cx/buffer.h	Mon Jan 31 17:15:59 2022 +0100
     1.3 @@ -48,6 +48,7 @@
     1.4  #define UCX_BUFFER_H
     1.5  
     1.6  #include "common.h"
     1.7 +#include "allocator.h"
     1.8  #include <stdio.h>
     1.9  
    1.10  #ifdef    __cplusplus
    1.11 @@ -82,6 +83,8 @@
    1.12           */
    1.13          unsigned char *bytes;
    1.14      };
    1.15 +    /** The allocator to use for automatic memory management. */
    1.16 +    CxAllocator *allocator;
    1.17      /** Current position of the buffer. */
    1.18      size_t pos;
    1.19      /** Current capacity (i.e. maximum size) of the buffer. */
    1.20 @@ -103,31 +106,34 @@
    1.21  typedef cx_buffer_s CxBuffer;
    1.22  
    1.23  /**
    1.24 - * Creates a new buffer.
    1.25 + * Initializes a fresh buffer.
    1.26   *
    1.27   * \note You may provide \c NULL as argument for \p space.
    1.28   * Then this function will allocate the space and enforce
    1.29   * the #CX_BUFFER_FREE_CONTENTS flag.
    1.30   *
    1.31 - * @param space pointer to the memory area, or <code>NULL</code> to allocate
    1.32 + * @param buffer the buffer to initialize
    1.33 + * @param space pointer to the memory area, or \c NULL to allocate
    1.34   * new memory
    1.35   * @param capacity the capacity of the buffer
    1.36 + * @param allocator the allocator this buffer shall use for automatic memory management
    1.37   * @param flags buffer features (see cx_buffer_s.flags)
    1.38 - * @return the new buffer
    1.39 + * @return zero on success, non-zero if a required allocation failed
    1.40   */
    1.41 -CxBuffer *cxBufferCreate(
    1.42 +int cxBufferInit(
    1.43 +        CxBuffer *buffer,
    1.44          void *space,
    1.45          size_t capacity,
    1.46 +        CxAllocator *allocator,
    1.47          int flags
    1.48  );
    1.49  
    1.50  /**
    1.51 - * Destroys a buffer.
    1.52 + * Destroys the buffer contents.
    1.53   *
    1.54 - * If the #CX_BUFFER_FREE_CONTENTS feature is enabled, the contents of the buffer
    1.55 - * are also freed.
    1.56 + * Has no effect if the #CX_BUFFER_FREE_CONTENTS feature is not enabled.
    1.57   *
    1.58 - * @param buffer the buffer to destroy
    1.59 + * @param buffer the buffer which contents shall be destroyed
    1.60   */
    1.61  void cxBufferDestroy(CxBuffer *buffer);
    1.62  

mercurial