Mercurial > hgrepos > Python2 > PyMuPDF
view mupdf-source/docs/reference/c/fitz/context.md @ 46:7ee69f120f19 default tip
>>>>> tag v1.26.5+1 for changeset b74429b0f5c4
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 11 Oct 2025 17:17:30 +0200 |
| parents | b50eed0cc0ef |
| children |
line wrap: on
line source
# Context Almost all functions in the MuPDF library take a `fz_context` structure as their first argument. The context is used for many things; primarily it holds the exception stack for our `setjmp` based exception handling. It also holds various caches and auxiliary contexts for font rendering and color management. Here is the code to create a Fitz context. The first two arguments are used if you need to use a custom memory allocator, and the third argument is a hint to much memory the various caches should be allowed to grow. The limit is only a soft limit. We may exceed it, but will start clearing out stale data to try to stay below the limit when possible. Setting it to a lower value will prevent the caches from growing out of hand if you are tight on memory. #include <mupdf/fitz.h> #include <stdio.h> #include <stdlib.h> main() { fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED); if (!ctx) { fprintf(stderr, "Failed to create a new Fitz context!\n"); return EXIT_FAILURE; } ... do stuff ... fz_drop_context(ctx); return EXIT_SUCCESS; }
