5.2 Creation

To create a context, use fz_new_context:

/* 
   fz_new_context: Allocate context containing global state. 
 
   The global state contains an exception stack, resource store, 
   etc. Most functions in MuPDF take a context argument to be 
   able to reference the global state. See fz_drop_context for 
   freeing an allocated context. 
 
   alloc: Supply a custom memory allocator through a set of 
   function pointers. Set to NULL for the standard library 
   allocator. The context will keep the allocator pointer, so the 
   data it points to must not be modified or freed during the 
   lifetime of the context. 
 
   locks: Supply a set of locks and functions to lock/unlock 
   them, intended for multi-threaded applications. Set to NULL 
   when using MuPDF in a single-threaded applications. The 
   context will keep the locks pointer, so the data it points to 
   must not be modified or freed during the lifetime of the 
   context. 
 
   max_store: Maximum size in bytes of the resource store, before 
   it will start evicting cached resources such as fonts and 
   images. FZ_STORE_UNLIMITED can be used if a hard limit is not 
   desired. Use FZ_STORE_DEFAULT to get a reasonable size. 
 
   Does not throw exceptions, but may return NULL. 
*/ 
fz_context *fz_new_context(const fz_alloc_context *alloc, const fz_locks_context *locks, unsigned int max_store);

For example, a simple, single threaded program using the standard allocator can just use:

fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);