## xmlmemory

xmlmemory —

## Synopsis

    #define     DEBUG_MEMORY
    void        (*xmlFreeFunc)                  (void *mem);
    void*       (*xmlMallocFunc)                (size_t size);
    void*       (*xmlReallocFunc)               (void *mem,
                                                 size_t size);
    char*       (*xmlStrdupFunc)                (const char *str);
    int         xmlMemSetup                     (xmlFreeFunc freeFunc,
                                                 xmlMallocFunc mallocFunc,
                                                 xmlReallocFunc reallocFunc,
                                                 xmlStrdupFunc strdupFunc);
    int         xmlMemGet                       (xmlFreeFunc *freeFunc,
                                                 xmlMallocFunc *mallocFunc,
                                                 xmlReallocFunc *reallocFunc,
                                                 xmlStrdupFunc *strdupFunc);
    int         xmlGcMemSetup                   (xmlFreeFunc freeFunc,
                                                 xmlMallocFunc mallocFunc,
                                                 xmlMallocFunc mallocAtomicFunc,
                                                 xmlReallocFunc reallocFunc,
                                                 xmlStrdupFunc strdupFunc);
    int         xmlGcMemGet                     (xmlFreeFunc *freeFunc,
                                                 xmlMallocFunc *mallocFunc,
                                                 xmlMallocFunc *mallocAtomicFunc,
                                                 xmlReallocFunc *reallocFunc,
                                                 xmlStrdupFunc *strdupFunc);
    int         xmlInitMemory                   (void);
    int         xmlMemUsed                      (void);
    void        xmlMemDisplay                   (FILE *fp);
    void        xmlMemShow                      (FILE *fp,
                                                 int nr);
    void        xmlMemoryDump                   (void);
    void*       xmlMemMalloc                    (size_t size);
    void*       xmlMemRealloc                   (void *ptr,
                                                 size_t size);
    void        xmlMemFree                      (void *ptr);
    char*       xmlMemoryStrdup                 (const char *str);
    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);
    #define     xmlMalloc                       (size)
    #define     xmlMallocAtomic                 (size)
    #define     xmlRealloc                      (ptr, size)
    #define     xmlMemStrdup                    (str)

## Description

## Details

### DEBUG_MEMORY

    #define DEBUG_MEMORY

DEBUG_MEMORY replaces the allocator with a collect and debug shell to the libc allocator. DEBUG_MEMORY should only be activated when debugging libxml i.e. if libxml has been configured with --with-debug-mem too.

### xmlFreeFunc ()

    void        (*xmlFreeFunc)                  (void *mem);

Signature for a free() implementation.

`mem` : | an already allocated block of memory

### xmlMallocFunc ()

    void*       (*xmlMallocFunc)                (size_t size);

Signature for a malloc() implementation.

`size` : | the size requested in bytes

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

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

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

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

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

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

### xmlInitMemory ()

    int         xmlInitMemory                   (void);

Initialize the memory layer.

Returns : | 0 on success

### xmlMemUsed ()

    int         xmlMemUsed                      (void);

Provides the amount of memory currently allocated

Returns : | an int representing the amount of memory allocated.

### xmlMemDisplay ()

    void        xmlMemDisplay                   (FILE *fp);

show in-extenso the memory blocks allocated

`fp` : | a FILE descriptor used as the output file, if NULL, the result is written to the file .memorylist

### xmlMemShow ()

    void        xmlMemShow                      (FILE *fp,
                                                 int nr);

show a show display of the memory allocated, and dump the `nr` last allocated areas which were not freed

`fp` : | a FILE descriptor used as the output file
`nr` : | number of entries to dump

### xmlMemoryDump ()

    void        xmlMemoryDump                   (void);

Dump in-extenso the memory blocks allocated to the file .memorylist

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

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

### xmlMemFree ()

    void        xmlMemFree                      (void *ptr);

a free() equivalent, with error checking.

`ptr` : | the memory block pointer

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

### xmlMallocLoc ()

    void*       xmlMallocLoc                    (size_t size,
                                                 const char *file,
                                                 int line);

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

`size` : | an int specifying the size in byte to allocate.
`file` : | the file name or NULL
`line` : | the line number

### xmlReallocLoc ()

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

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.
`file` : | the file name or NULL
`line` : | the line number

### xmlMallocAtomicLoc ()

    void*       xmlMallocAtomicLoc              (size_t size,
                                                 const char *file,
                                                 int line);

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

`size` : | an int specifying the size in byte to allocate.
`file` : | the file name or NULL
`line` : | the line number

### xmlMemStrdupLoc ()

    char*       xmlMemStrdupLoc                 (const char *str,
                                                 const char *file,
                                                 int line);

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

`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.

### xmlMalloc()

    #define     xmlMalloc(size)

Wrapper for the malloc() function used in the XML library.

`size` : | number of bytes to allocate

### xmlMallocAtomic()

    #define     xmlMallocAtomic(size)

Wrapper for the malloc() function used in the XML library for allocation of block not containing pointers to other areas.

`size` : | number of bytes to allocate

### xmlRealloc()

    #define     xmlRealloc(ptr, size)

Wrapper for the realloc() function used in the XML library.

`ptr` : | pointer to the existing allocated area
`size` : | number of bytes to allocate

### xmlMemStrdup()

    #define     xmlMemStrdup(str)

Wrapper for the strdup() function, xmlStrdup() is usually preferred.

`str` : | pointer to the existing string