xmlmemory: interface for the memory allocator

## xmlmemory

xmlmemory - interface for the memory allocator

provides interfaces for the memory allocator, including debugging capabilities.

Author(s): Daniel Veillard

## Synopsis

    void	xmlCleanupMemory		(void);
    typedef void xmlFreeFunc			(void * mem);
    int	xmlGcMemGet			(xmlFreeFunc * freeFunc,
    					 xmlMallocFunc * mallocFunc,
    					 xmlMallocFunc * mallocAtomicFunc,
    					 xmlReallocFunc * reallocFunc,
    					 xmlStrdupFunc * strdupFunc);
    int	xmlGcMemSetup			(xmlFreeFunc freeFunc,
    					 xmlMallocFunc mallocFunc,
    					 xmlMallocFunc mallocAtomicFunc,
    					 xmlReallocFunc reallocFunc,
    					 xmlStrdupFunc strdupFunc);
    int	xmlInitMemory			(void);
    void *	xmlMallocAtomicLoc		(size_t size,
    					 const char * file,
    					 int line);
    typedef void * xmlMallocFunc			(size_t size);
    void *	xmlMallocLoc			(size_t size,
    					 const char * file,
    					 int line);
    int	xmlMemBlocks			(void);
    void	xmlMemDisplay			(FILE * fp);
    void	xmlMemDisplayLast		(FILE * fp,
    					 long nbBytes);
    void	xmlMemFree			(void * ptr);
    int	xmlMemGet			(xmlFreeFunc * freeFunc,
    					 xmlMallocFunc * mallocFunc,
    					 xmlReallocFunc * reallocFunc,
    					 xmlStrdupFunc * strdupFunc);
    void *	xmlMemMalloc			(size_t size);
    void *	xmlMemRealloc			(void * ptr,
    					 size_t size);
    int	xmlMemSetup			(xmlFreeFunc freeFunc,
    					 xmlMallocFunc mallocFunc,
    					 xmlReallocFunc reallocFunc,
    					 xmlStrdupFunc strdupFunc);
    void	xmlMemShow			(FILE * fp,
    					 int nr);
    size_t	xmlMemSize			(void * ptr);
    char *	xmlMemStrdupLoc			(const char * str,
    					 const char * file,
    					 int line);
    int	xmlMemUsed			(void);
    void	xmlMemoryDump			(void);
    char *	xmlMemoryStrdup			(const char * str);
    typedef void * xmlReallocFunc			(void * mem,
    					 size_t size);
    void *	xmlReallocLoc			(void * ptr,
    					 size_t size,
    					 const char * file,
    					 int line);
    typedef char * xmlStrdupFunc			(const char * str);

## Description

## Details

### Function type xmlFreeFunc

    void	xmlFreeFunc			(void * mem)

Signature for a free() implementation.

`mem`: | an already allocated block of memory

### Function type xmlMallocFunc

    void *	xmlMallocFunc			(size_t size)

Signature for a malloc() implementation.

`size`: | the size requested in bytes
`Returns`: | a pointer to the newly allocated block or NULL in case of error.

### Function type xmlReallocFunc

    void *	xmlReallocFunc			(void * mem,
    					 size_t size)

Signature for a realloc() implementation.

`mem`: | an already allocated block of memory
`size`: | the new size requested in bytes
`Returns`: | a pointer to the newly reallocated block or NULL in case of error.

### Function type xmlStrdupFunc

    char *	xmlStrdupFunc			(const char * str)

Signature for an strdup() implementation.

`str`: | a zero terminated string
`Returns`: | the copy of the string or NULL in case of error.

### Variable xmlFree

    xmlFreeFunc xmlFree;

@mem: an already allocated block of memory The variable holding the libxml free() implementation

### Variable xmlMalloc

    xmlMallocFunc xmlMalloc;

@size: the size requested in bytes The variable holding the libxml malloc() implementation Returns a pointer to the newly allocated block or NULL in case of error

### Variable xmlMallocAtomic

    xmlMallocFunc xmlMallocAtomic;

@size: the size requested in bytes The variable holding the libxml malloc() implementation for atomic data (i.e. blocks not containing pointers), useful when using a garbage collecting allocator. Returns a pointer to the newly allocated block or NULL in case of error

### Variable xmlMemStrdup

    xmlStrdupFunc xmlMemStrdup;

@str: a zero terminated string The variable holding the libxml strdup() implementation Returns the copy of the string or NULL in case of error

### Variable xmlRealloc

    xmlReallocFunc xmlRealloc;

@mem: an already allocated block of memory @size: the new size requested in bytes The variable holding the libxml realloc() implementation Returns a pointer to the newly reallocated block or NULL in case of error

### 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

`freeFunc`: | place to save the free() function in use
`mallocFunc`: | place to save the malloc() function in use
`mallocAtomicFunc`: | place to save the atomic malloc() function in use
`reallocFunc`: | place to save the realloc() function in use
`strdupFunc`: | place 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 Should this be blocked if there was already some allocations done ?

`freeFunc`: | the free() function to use
`mallocFunc`: | the malloc() function to use
`mallocAtomicFunc`: | the malloc() function to use for atomic allocations
`reallocFunc`: | the realloc() function to use
`strdupFunc`: | the 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

`size`: | an unsigned int specifying the size in byte to allocate.
`file`: | the file name or NULL
`line`: | the 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

`size`: | an int specifying the size in byte to allocate.
`file`: | the file name or NULL
`line`: | the 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.

`fp`: | a FILE descriptor

### xmlMemDisplayLast ()

    void	xmlMemDisplayLast		(FILE * fp,
    					 long nbBytes)

DEPRECATED: This feature was removed.

`fp`: | a FILE descriptor
`nbBytes`: | the amount of memory to dump

### xmlMemFree ()

    void	xmlMemFree			(void * ptr)

a free() equivalent, with error checking.

`ptr`: | the memory block pointer

### xmlMemGet ()

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

Provides the memory access functions set currently in use

`freeFunc`: | place to save the free() function in use
`mallocFunc`: | place to save the malloc() function in use
`reallocFunc`: | place to save the realloc() function in use
`strdupFunc`: | place 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.

`size`: | an int specifying the size in byte to allocate.
`Returns`: | a pointer to the allocated area or NULL in case of lack of memory.

### xmlMemRealloc ()

    void *	xmlMemRealloc			(void * ptr,
    					 size_t size)

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

`ptr`: | the initial memory block pointer
`size`: | an 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 ?

`freeFunc`: | the free() function to use
`mallocFunc`: | the malloc() function to use
`reallocFunc`: | the realloc() function to use
`strdupFunc`: | the strdup() function to use
`Returns`: | 0 on success

### xmlMemShow ()

    void	xmlMemShow			(FILE * fp,
    					 int nr)

DEPRECATED: This feature was removed.

`fp`: | a FILE descriptor
`nr`: | number of entries to dump

### xmlMemSize ()

    size_t	xmlMemSize			(void * ptr)

`ptr`: | pointer 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

`str`: | the initial string pointer
`file`: | the file name or NULL
`line`: | the 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.

### xmlMemoryDump ()

    void	xmlMemoryDump			(void)

DEPRECATED: This feature was removed.

### xmlMemoryStrdup ()

    char *	xmlMemoryStrdup			(const char * str)

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

`str`: | the initial string pointer
`Returns`: | a pointer to the new string or NULL if allocation error occurred.

### xmlReallocLoc ()

    void *	xmlReallocLoc			(void * ptr,
    					 size_t size,
    					 const char * file,
    					 int line)

DEPRECATED: don't use

`ptr`: | the initial memory block pointer
`size`: | an int specifying the size in byte to allocate.
`file`: | the file name or NULL
`line`: | the line number
`Returns`: | a pointer to the allocated area or NULL in case of lack of memory.