comparison mupdf-source/docs/reference/c/fitz/context.md @ 3:2c135c81b16c

MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 15 Sep 2025 11:44:09 +0200
parents b50eed0cc0ef
children
comparison
equal deleted inserted replaced
0:6015a75abc2d 3:2c135c81b16c
1 # Context
2
3 Almost all functions in the MuPDF library take a `fz_context` structure as
4 their first argument. The context is used for many things; primarily it holds
5 the exception stack for our `setjmp` based exception handling. It also holds
6 various caches and auxiliary contexts for font rendering and color management.
7
8 Here is the code to create a Fitz context. The first two arguments are used if
9 you need to use a custom memory allocator, and the third argument is a hint to
10 much memory the various caches should be allowed to grow. The limit is only a
11 soft limit. We may exceed it, but will start clearing out stale data to try to
12 stay below the limit when possible. Setting it to a lower value will prevent
13 the caches from growing out of hand if you are tight on memory.
14
15 #include <mupdf/fitz.h>
16
17 #include <stdio.h>
18 #include <stdlib.h>
19
20 main()
21 {
22 fz_context *ctx = fz_new_context(NULL, NULL, FZ_STORE_UNLIMITED);
23 if (!ctx) {
24 fprintf(stderr, "Failed to create a new Fitz context!\n");
25 return EXIT_FAILURE;
26 }
27
28 ... do stuff ...
29
30 fz_drop_context(ctx);
31 return EXIT_SUCCESS;
32 }