HTML Tidy  0.1
_TidyAllocator Struct Reference

#include <tidy.h>

Data Fields

const TidyAllocatorVtblvtbl

Detailed Description

An allocator. To create your own allocator, do something like the following:

typedef struct _MyAllocator { TidyAllocator base; ...other custom allocator state... } MyAllocator;

void* MyAllocator_alloc(TidyAllocator <em>base, void *block, size_t nBytes) { MyAllocator *self = (MyAllocator)base; ... } (etc)

static const TidyAllocatorVtbl MyAllocatorVtbl = { MyAllocator_alloc, MyAllocator_realloc, MyAllocator_free, MyAllocator_panic };

myAllocator allocator; TidyDoc doc;

allocator.base.vtbl = &MyAllocatorVtbl; ...initialise allocator specific state... doc = tidyCreateWithAllocator(&allocator); ...

Although this looks slightly long winded, the advantage is that to create a custom allocator you simply need to set the vtbl pointer correctly. The vtbl itself can reside in static/global data, and hence does not need to be initialised each time an allocator is created, and furthermore the memory is shared amongst all created allocators.


The documentation for this struct was generated from the following file: