libxml2
Loading...
Searching...
No Matches
xmlmemory.h File Reference

interface for the memory allocator More...

Typedefs

typedef void(* xmlFreeFunc) (void *mem)
 Signature for a free() implementation.
typedef void *(* xmlMallocFunc) (size_t size)
 Signature for a malloc() implementation.
typedef void *(* xmlReallocFunc) (void *mem, size_t size)
 Signature for a realloc() implementation.
typedef char *(* xmlStrdupFunc) (const char *str)
 Signature for an strdup() implementation.

Functions

int xmlMemSetup (xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc)
 Override the default memory access functions with a new set This has to be called before any other libxml routines !
int xmlMemGet (xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc)
 Provides the memory access functions set currently in use.
int xmlGcMemSetup (xmlFreeFunc freeFunc, xmlMallocFunc mallocFunc, xmlMallocFunc mallocAtomicFunc, xmlReallocFunc reallocFunc, xmlStrdupFunc strdupFunc)
 Override the default memory access functions with a new set This has to be called before any other libxml routines !
int xmlGcMemGet (xmlFreeFunc *freeFunc, xmlMallocFunc *mallocFunc, xmlMallocFunc *mallocAtomicFunc, xmlReallocFunc *reallocFunc, xmlStrdupFunc *strdupFunc)
 Provides the memory access functions set currently in use The mallocAtomicFunc is specialized for atomic block allocations (i.e.
int xmlInitMemory (void)
void xmlCleanupMemory (void)
size_t xmlMemSize (void *ptr)
int xmlMemUsed (void)
 Provides the amount of memory currently allocated.
int xmlMemBlocks (void)
 Provides the number of memory areas currently allocated.
void xmlMemDisplay (FILE *fp)
void xmlMemDisplayLast (FILE *fp, long nbBytes)
void xmlMemShow (FILE *fp, int nr)
void xmlMemoryDump (void)
void * xmlMemMalloc (size_t size)
 a malloc() equivalent, with logging of the allocation info.
void * xmlMemRealloc (void *ptr, size_t size)
 a realloc() equivalent, with logging of the allocation info.
void xmlMemFree (void *ptr)
 a free() equivalent, with error checking.
char * xmlMemoryStrdup (const char *str)
 a strdup() equivalent, with logging of the allocation info.
void * xmlMallocLoc (size_t size, const char *file, int line)
void * xmlReallocLoc (void *ptr, size_t size, const char *file, int line)
void * xmlMallocAtomicLoc (size_t size, const char *file, int line)
char * xmlMemStrdupLoc (const char *str, const char *file, int line)

Variables

xmlMallocFunc xmlMalloc
 The variable holding the libxml malloc() implementation.
xmlMallocFunc xmlMallocAtomic
 The variable holding the libxml malloc() implementation for atomic data (i.e.
xmlReallocFunc xmlRealloc
 The variable holding the libxml realloc() implementation.
xmlFreeFunc xmlFree
 The variable holding the libxml free() implementation.
xmlStrdupFunc xmlMemStrdup
 The variable holding the libxml strdup() implementation.

Detailed Description

interface for the memory allocator

provides interfaces for the memory allocator, including debugging capabilities.

Author
Daniel Veillard

Typedef Documentation

◆ xmlFreeFunc

typedef void(* xmlFreeFunc) (void *mem)

Signature for a free() implementation.

Parameters
meman already allocated block of memory

◆ xmlMallocFunc

typedef void *(* xmlMallocFunc) (size_t size)

Signature for a malloc() implementation.

Parameters
sizethe size requested in bytes
Returns
a pointer to the newly allocated block or NULL in case of error.

◆ xmlReallocFunc

typedef void *(* xmlReallocFunc) (void *mem, size_t size)

Signature for a realloc() implementation.

Parameters
meman already allocated block of memory
sizethe new size requested in bytes
Returns
a pointer to the newly reallocated block or NULL in case of error.

◆ xmlStrdupFunc

typedef char *(* xmlStrdupFunc) (const char *str)

Signature for an strdup() implementation.

Parameters
stra zero terminated string
Returns
the copy of the string or NULL in case of error.

Function Documentation

◆ xmlCleanupMemory()

void xmlCleanupMemory ( void )
Deprecated
This function is a no-op. Call xmlCleanupParser to free global state but see the warnings there. xmlCleanupParser should be only called once at program exit. In most cases, you don't have call cleanup functions at all.

◆ xmlGcMemGet()

int xmlGcMemGet ( xmlFreeFunc * freeFunc,
xmlMallocFunc * mallocFunc,
xmlMallocFunc * mallocAtomicFunc,
xmlReallocFunc * reallocFunc,
xmlStrdupFunc * strdupFunc )

Provides the memory access functions set currently in use The mallocAtomicFunc is specialized for atomic block allocations (i.e.

of areas useful for garbage collected memory allocators

Deprecated
Use xmlMemGet.
Parameters
freeFuncplace to save the free() function in use
mallocFuncplace to save the malloc() function in use
mallocAtomicFuncplace to save the atomic malloc() function in use
reallocFuncplace to save the realloc() function in use
strdupFuncplace to save the strdup() function in use
Returns
0 on success

◆ xmlGcMemSetup()

int xmlGcMemSetup ( xmlFreeFunc freeFunc,
xmlMallocFunc mallocFunc,
xmlMallocFunc mallocAtomicFunc,
xmlReallocFunc reallocFunc,
xmlStrdupFunc strdupFunc )

Override the default memory access functions with a new set This has to be called before any other libxml routines !

The mallocAtomicFunc is specialized for atomic block allocations (i.e. of areas useful for garbage collected memory allocators

Deprecated
Use xmlMemSetup.

Should this be blocked if there was already some allocations done ?

Parameters
freeFuncthe free() function to use
mallocFuncthe malloc() function to use
mallocAtomicFuncthe malloc() function to use for atomic allocations
reallocFuncthe realloc() function to use
strdupFuncthe strdup() function to use
Returns
0 on success

◆ xmlInitMemory()

int xmlInitMemory ( void )
Deprecated
Alias for xmlInitParser.
Returns
0.

◆ xmlMallocAtomicLoc()

void * xmlMallocAtomicLoc ( size_t size,
const char * file,
int line )
Deprecated
don't use
Parameters
sizean unsigned int specifying the size in byte to allocate.
filethe file name or NULL
linethe line number
Returns
a pointer to the allocated area or NULL in case of lack of memory.

◆ xmlMallocLoc()

void * xmlMallocLoc ( size_t size,
const char * file,
int line )
Deprecated
don't use
Parameters
sizean int specifying the size in byte to allocate.
filethe file name or NULL
linethe line number
Returns
a pointer to the allocated area or NULL in case of lack of memory.

◆ xmlMemBlocks()

int xmlMemBlocks ( void )

Provides the number of memory areas currently allocated.

Returns
an int representing the number of blocks

◆ xmlMemDisplay()

void xmlMemDisplay ( FILE * fp)
Deprecated
This feature was removed.
Parameters
fpa FILE descriptor

◆ xmlMemDisplayLast()

void xmlMemDisplayLast ( FILE * fp,
long nbBytes )
Deprecated
This feature was removed.
Parameters
fpa FILE descriptor
nbBytesthe amount of memory to dump

◆ xmlMemFree()

void xmlMemFree ( void * ptr)

a free() equivalent, with error checking.

Parameters
ptrthe memory block pointer

◆ xmlMemGet()

int xmlMemGet ( xmlFreeFunc * freeFunc,
xmlMallocFunc * mallocFunc,
xmlReallocFunc * reallocFunc,
xmlStrdupFunc * strdupFunc )

Provides the memory access functions set currently in use.

Parameters
freeFuncplace to save the free() function in use
mallocFuncplace to save the malloc() function in use
reallocFuncplace to save the realloc() function in use
strdupFuncplace to save the strdup() function in use
Returns
0 on success

◆ xmlMemMalloc()

void * xmlMemMalloc ( size_t size)

a malloc() equivalent, with logging of the allocation info.

Parameters
sizean int specifying the size in byte to allocate.
Returns
a pointer to the allocated area or NULL in case of lack of memory.

◆ xmlMemoryDump()

void xmlMemoryDump ( void )
Deprecated
This feature was removed.

◆ xmlMemoryStrdup()

char * xmlMemoryStrdup ( const char * str)

a strdup() equivalent, with logging of the allocation info.

Parameters
strthe initial string pointer
Returns
a pointer to the new string or NULL if allocation error occurred.

◆ xmlMemRealloc()

void * xmlMemRealloc ( void * ptr,
size_t size )

a realloc() equivalent, with logging of the allocation info.

Parameters
ptrthe initial memory block pointer
sizean int specifying the size in byte to allocate.
Returns
a pointer to the allocated area or NULL in case of lack of memory.

◆ xmlMemSetup()

int xmlMemSetup ( xmlFreeFunc freeFunc,
xmlMallocFunc mallocFunc,
xmlReallocFunc reallocFunc,
xmlStrdupFunc strdupFunc )

Override the default memory access functions with a new set This has to be called before any other libxml routines !

Should this be blocked if there was already some allocations done ?

Parameters
freeFuncthe free() function to use
mallocFuncthe malloc() function to use
reallocFuncthe realloc() function to use
strdupFuncthe strdup() function to use
Returns
0 on success

◆ xmlMemShow()

void xmlMemShow ( FILE * fp,
int nr )
Deprecated
This feature was removed.
Parameters
fpa FILE descriptor
nrnumber of entries to dump

◆ xmlMemSize()

size_t xmlMemSize ( void * ptr)
Parameters
ptrpointer to the memory allocation
Returns
the size of a memory allocation.

◆ xmlMemStrdupLoc()

char * xmlMemStrdupLoc ( const char * str,
const char * file,
int line )
Deprecated
don't use
Parameters
strthe initial string pointer
filethe file name or NULL
linethe line number
Returns
a pointer to the new string or NULL if allocation error occurred.

◆ xmlMemUsed()

int xmlMemUsed ( void )

Provides the amount of memory currently allocated.

Returns
an int representing the amount of memory allocated.

◆ xmlReallocLoc()

void * xmlReallocLoc ( void * ptr,
size_t size,
const char * file,
int line )
Deprecated
don't use
Parameters
ptrthe initial memory block pointer
sizean int specifying the size in byte to allocate.
filethe file name or NULL
linethe line number
Returns
a pointer to the allocated area or NULL in case of lack of memory.

Variable Documentation

◆ xmlMallocAtomic

xmlMallocFunc xmlMallocAtomic
extern

The variable holding the libxml malloc() implementation for atomic data (i.e.

blocks not containing pointers), useful when using a garbage collecting allocator.

Deprecated
Use xmlMalloc