EPICS Base  7.0.6.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions
dbmf.h File Reference

A library to manage storage that is allocated and quickly freed. More...

#include <stdlib.h>
#include "libComAPI.h"
Include dependency graph for dbmf.h:

Go to the source code of this file.

Functions

LIBCOM_API int dbmfInit (size_t size, int chunkItems)
 Initialize the facility. More...
 
LIBCOM_API void * dbmfMalloc (size_t bytes)
 Allocate memory. More...
 
LIBCOM_API char * dbmfStrdup (const char *str)
 Duplicate a string. More...
 
LIBCOM_API char * dbmfStrndup (const char *str, size_t len)
 Duplicate a string (up to len bytes). More...
 
LIBCOM_API char * dbmfStrcat3 (const char *lhs, const char *mid, const char *rhs)
 Concatenate three strings. More...
 
LIBCOM_API void dbmfFree (void *bytes)
 Free the memory allocated by dbmfMalloc. More...
 
LIBCOM_API void dbmfFreeChunks (void)
 Free all chunks that contain only free items.
 
LIBCOM_API int dbmfShow (int level)
 Show the status of the dbmf memory pool. More...
 

Detailed Description

Author
Jim Kowalkowski, Marty Kraimer

Database Macro/Free describes a facility that prevents memory fragmentation when temporary storage is being allocated and freed a short time later, at the same time that much longer-lived storage is also being allocated, such as when parsing items for the IOC database while also creating records.

Routines whin iocCore like dbLoadDatabase() have the following attributes:

Note
In some environment, e.g. vxWorks, this behavior causes severe memory fragmentation.
This facility should NOT be used by code that allocates storage and then keeps it for a considerable period of time before releasing. Such code should consider using the freeList library.

Definition in file dbmf.h.

Function Documentation

LIBCOM_API int dbmfInit ( size_t  size,
int  chunkItems 
)
Parameters
sizeThe maximum size request from dbmfMalloc() that will be allocated from the dbmf pool (Size is always made a multiple of 8).
chunkItemsEach time malloc() must be called size*chunkItems bytes are allocated.
Returns
0 on success, -1 if already initialized
Note
If dbmfInit() is not called before one of the other routines then it is automatically called with size=64 and chunkItems=10
LIBCOM_API void* dbmfMalloc ( size_t  bytes)
Parameters
bytesIf bytes > size then malloc() is used to allocate the memory.
Returns
Pointer to the newly-allocated memory, or NULL on failure.
LIBCOM_API char* dbmfStrdup ( const char *  str)

Create a copy of the input string.

Parameters
strPointer to the null-terminated string to be copied.
Returns
A pointer to the new copy, or NULL on failure.
LIBCOM_API char* dbmfStrndup ( const char *  str,
size_t  len 
)

Copy at most len bytes of the input string into a new buffer. If no nil terminator is seen in the first len bytes a nil terminator is added.

Parameters
strPointer to the null-terminated string to be copied.
lenMax number of bytes to copy.
Returns
A pointer to the new string, or NULL on failure.
LIBCOM_API char* dbmfStrcat3 ( const char *  lhs,
const char *  mid,
const char *  rhs 
)

Returns a pointer to a null-terminated string made by concatenating the three input strings.

Parameters
lhsStart string to which the others get concatenated to (left part).
midNext string to be concatenated to the lhs (mid part).
rhsLast string to be concatenated to the lhs+mid (right part).
Returns
A pointer to the new string, or NULL on failure.
LIBCOM_API void dbmfFree ( void *  bytes)
Parameters
bytesPointer to memory obtained from dbmfMalloc(), dbmfStrdup(), dbmfStrndup() or dbmfStrcat3().
LIBCOM_API int dbmfShow ( int  level)
Parameters
levelDetail level.
Returns
0.