1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-27 09:11:48 -07:00

Improve allocation example so that it demonstrate aligning up the size. explain why the mps doesn't do this for you. fix typo in scanning chapter.

Copied from Perforce
 Change: 183051
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Gareth Rees 2013-07-16 10:45:05 +01:00
parent 4732a1bca7
commit 300370fa63
2 changed files with 16 additions and 6 deletions

View file

@ -243,18 +243,28 @@ is thus::
mps_addr_t p;
obj_t obj;
size_t aligned_size = ALIGN(size); /* see note 1 */
do {
mps_res_t res = mps_reserve(&p, ap, size);
mps_res_t res = mps_reserve(&p, ap, aligned_size);
if (res != MPS_RES_OK) /* handle the error */;
/* p is now an ambiguous reference to the reserved block */
obj = p;
/* initialize obj */
} while (!mps_commit(ap, p, size));
} while (!mps_commit(ap, p, aligned_size)); /* see note 2 */
/* obj is now valid and managed by the MPS */
It is not necessary to worry about going around this loop many times:
:c:func:`mps_commit` can fail at most once per thread per
:term:`flip`.
.. note::
1. Here :c:func:`ALIGN` represents a function or macro that
rounds ``size`` up to the necessary alignment, which should be
at least as big as the alignment of the pool. (The reason that
the MPS does not do this rounding up for you is to provide more
opportunities for optimization: in many cases the required
alignment will be a constant that's known at compilation time.)
2. It is not necessary to worry about going around this loop many
times: :c:func:`mps_commit` can fail at most once per thread
per :term:`flip`.
.. c:function:: mps_res_t mps_reserve(mps_addr_t *p_o, mps_ap_t ap, size_t size)

View file

@ -212,7 +212,7 @@ The MPS does not require you to :term:`fix` all your :term:`references`. But if
These optimizations can be tricky to make correct, and can make the
system fragile (for example, it may break if you start using a
different :term:`pool class`), so it usually safest to fix all
different :term:`pool class`), so it is usually safest to fix all
references.