Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_VSBalloc - create librock variable-sized contiguous buffer (librock_VSB)
librock_VSBallocXA - create librock_VSB for externally allocated buffer
librock_VSBalloccpy - create librock_VSB and preload
librock_VSBrealloc - decrease or expand a librock_VSB

librock_VSBsz - Ensure '\0' follows the buffer, and return pointer to buffer.

librock_VSBfree - deallocate storage associated with a librock_VSB

#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/mstruct.h>

struct librock_VSB_s *
librock_VSBalloc();

struct librock_VSB_s *
librock_VSBallocXA(
    const void *p,
    int len
);

struct librock_VSB_s *
librock_VSBalloccpy(
    const void *ptr,
    int len
);

void
librock_VSBfree(
    struct librock_VSB_s *v
);

char *
librock_VSBsz(
    struct librock_VSB_s *v
);


DESCRIPTION

librock_VSBalloc returns a pointer to a freshly malloc'ed librock_VSB_s structure and malloc's a starting buffer. The librock_VSB_s describes a contiguous block of memory which can expand and contract as needed. (Some "slack" overallocation is performed to reduce buffer size changes.)

Memory is obtained from malloc(), but callers must use the librock_VSB routines to manage the VSB.

The allocated buffer size can be up to INT_MAX. Callers can access the structure members "buf" (pointer) and "inbuf" (count of bytes) but should never change them.

Use librock_VSBallocXA() to create a librock_VSB structure which describes a buffer already externally allocated. It will be "WriteDisabled."

Use librock_VSBalloccpy() to create a librock_VSB structure and copy in data initially.

Use librock_VSBrealloc() to resize a buffer. The VSB.inbuf member is not changed. Returns 0 if memory realloc fails.

Typical use is to create a workspace for data, especially non-string data. librock_VSB_s is useful as a primitive in the implementation of other basic data structures, such as lists of pointers, or structures.

#ifdef librock_TYPICAL_USE_VSBalloc
    #include <librock/mstruct.h>
    struct librock_VSB_s *v = librock_VSBalloc();

    librock_VSBAppend(v,"is ",3);
    librock_VSBInsert(v,0,"this ",5);
    printf("%s\n",librock_VSBsz(v));
    librock_VSBfree(v);
#endif
For C++ uses, see the librock_CVsb wrapper class. See also the librock_VSIL_s routines.

USES

    malloc()   // #ifndef librock_fmalloc
    realloc()  // #ifndef librock_fmalloc
    free()     // #ifndef librock_fmalloc
    memcpy()   // #ifndef librock_memcpy
    memmove()  // #ifndef librock_memcpy
    memset()   // #ifndef librock_memcpy
    // Uses macros for memory operations librock_fmalloc
    // librock_ffree librock_frealloc librock_memcpy librock_memmove
    // and librock_memset.  If those macros are not defined at
    // compile time, they are set to use malloc(), realloc(),
    // free(), memcpy(), memmove(), and memset()



LICENSE

  Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com
  Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block.
  License text in <librock/license/librock.txt> librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45

Source Code

./exec/struct/vsb.c (implementation, plus source of this manual page)

Tests and Supported Platform Types

This is a representative sample. Librock code is highly portable. For a particular platform not reported here, request paid support

librock_VSBalloc passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_VSBalloc passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_VSBallocXA passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_VSBallocXA passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_VSBalloccpy passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_VSBalloccpy passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_VSBfree passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_VSBfree passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)
librock_VSBsz passed tests in tvsbop (Unix/Linux/BSD: 2002/08/08 sys=FreeBSD using gcc)
librock_VSBsz passed tests in tvsbop_main (WIN32: 2002/08/08 sys=NT 4.0 using MSVC)


This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)

Want to help? We welcome comments, patches. -- Need help? Request paid support.