1 (** Mark objects as 'ancient' so they are taken out of the OCaml heap. *)
5 val mark : 'a -> 'a ancient
6 (** [mark obj] copies [obj] and all objects referenced
7 * by [obj] out of the OCaml heap. It returns the proxy
10 * The copy of [obj] accessed through the proxy MUST NOT be mutated.
12 * If [obj] represents a large object, then it is a good
13 * idea to call {!Gc.compact} after marking to recover the
17 val follow : 'a ancient -> 'a
18 (** Follow proxy link to out of heap object.
20 * @raise [Invalid_argument "deleted"] if the object has been deleted.
23 val delete : 'a ancient -> unit
24 (** [delete obj] deletes ancient object [obj].
26 * @raise [Invalid_argument "deleted"] if the object has been deleted.
28 * Forgetting to delete an ancient object results in a memory leak.
31 val is_ancient : 'a -> bool
32 (** [is_ancient ptr] returns true if [ptr] is an object on the ancient
36 val address_of : 'a -> nativeint
37 (** [address_of obj] returns the address of [obj], or [0n] if [obj]
41 (** {6 Shared memory mappings} *)
44 (** Memory descriptor handle. *)
46 val attach : Unix.file_descr -> nativeint -> md
47 (** [attach fd baseaddr] attaches to a new or existing file
48 * which may contain shared objects.
50 * Initially [fd] should be a read/writable, zero-length file
51 * (for example you could create this using {!Unix.openfile} and
52 * passing the flags [O_RDWR], [O_TRUNC], [O_CREAT]).
53 * One or more objects can then be shared in this file
54 * using {!Unix.share}.
56 * For new files, [baseaddr] specifies the virtual address to
57 * map the file. Specifying [Nativeint.zero] ([0n]) here lets [mmap(2)]
58 * choose this, but on some platforms (notably Linux/AMD64)
59 * [mmap] chooses very unwisely, tending to map the memory
60 * just before [libc] with hardly any headroom to grow. If
61 * you encounter this sort of problem (usually a segfault or
62 * illegal instruction inside libc), then look at [/proc/PID/maps]
63 * and choose a more suitable address.
65 * If the file was created previously, then the [baseaddr] is
66 * ignored. The underlying [mmalloc] library will map the
67 * file in at the same place as before.
70 val detach : md -> unit
71 (** [detach md] detaches from an existing file, and closes it.
74 val share : md -> int -> 'a -> 'a ancient
75 (** [share md key obj] does the same as {!Ancient.mark} except
76 * that instead of copying the object into local memory, it
77 * writes it into memory which is backed by the attached file.
79 * Shared mappings created this way may be shared between
80 * other OCaml processes which can access the underlying
81 * file. See {!Ancient.attach}, {!Ancient.detach}.
83 * More than one object can be stored in a file. The [key]
84 * parameter controls which object is written/overwritten by [share].
85 * If you do not wish to use this feature, just pass [0]
88 * Do not call {!Ancient.delete} on a mapping created like this.
89 * Instead, call {!Ancient.detach} and, if necessary, delete the
92 * Caution when sharing files/objects between processes:
93 * The underlying [mmalloc] library does not do any sort of
94 * locking, so all calls to [share] must ensure that they have
95 * exclusive access to the underlying file while in progress.
96 * (Other processes should not even call {!Ancient.get} while
97 * this is happening, but it seems safe to be just reading an
98 * ancient object from the file).
101 val get : md -> int -> 'a ancient
102 (** [get md key] returns the object indexed by [key] in the
105 * For details of the [key] parameter see {!Ancient.share}.
107 * You need to annotate the returned object with the correct
108 * type. As with the Marshal module, there is no type checking,
109 * and setting the wrong type will likely cause a segfault
110 * or undefined behaviour. Note that the returned object has
111 * type [sometype ancient], not just [sometype].
113 * @raises [Not_found] if no object is associated with the key.
116 (** {6 Additional information} *)
119 i_size : int; (** Allocated size, bytes. *)
121 (** Extra information fields. See {!Ancient.mark_info} and
122 * {!Ancient.share_info}.
125 val mark_info : 'a -> 'a ancient * info
126 (** Same as {!Ancient.mark}, but also returns some extra information. *)
128 val share_info : md -> int -> 'a -> 'a ancient * info
129 (** Same as {!Ancient.share}, but also returns some extra information. *)