mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-08 04:30:45 -08:00
Mps example hwgc02.c: move from mps_alloc to ap: mps_reserve..mps_commit
Copied from Perforce Change: 159152 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
61435c3209
commit
0bcd2a1cfd
1 changed files with 29 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/* Simple C client of the MPS, with LO pool and VM arena */
|
||||
/* Simple C client of the MPS, with ap in LO pool and VM arena */
|
||||
/* $Id$ */
|
||||
|
||||
#include <stdlib.h> /* for malloc */
|
||||
|
|
@ -60,6 +60,7 @@ int main(void)
|
|||
mps_arena_t ArenaDemo = NULL;
|
||||
mps_fmt_t FormatDemo = NULL;
|
||||
mps_pool_t PoolDemo = NULL;
|
||||
mps_ap_t ApDemo = NULL;
|
||||
|
||||
mps_res_t res;
|
||||
|
||||
|
|
@ -108,20 +109,38 @@ int main(void)
|
|||
|
||||
report("Created pool", ArenaDemo, PoolDemo);
|
||||
}
|
||||
|
||||
{
|
||||
/* Create ap */
|
||||
|
||||
res = mps_ap_create(&ApDemo, PoolDemo);
|
||||
if (res != MPS_RES_OK) {
|
||||
printf("mps_ap_create: failed with res %d.\n", res);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
report("Created ap", ArenaDemo, PoolDemo);
|
||||
}
|
||||
|
||||
{
|
||||
/* Allocate memory */
|
||||
|
||||
size_t cbBuffer = 100;
|
||||
size_t cbBuffer = 256;
|
||||
void *p = NULL;
|
||||
|
||||
res = mps_alloc(&p, PoolDemo, cbBuffer);
|
||||
if (res != MPS_RES_OK) {
|
||||
printf("mps_alloc: failed with res %d.\n", res);
|
||||
exit(2);
|
||||
}
|
||||
do {
|
||||
res = mps_reserve(&p, ApDemo, cbBuffer);
|
||||
if (res != MPS_RES_OK) {
|
||||
printf("mps_reserve: failed with res %d.\n", res);
|
||||
exit(2);
|
||||
}
|
||||
/* Initialise my object here -- ie. make it valid. */
|
||||
/* (In this example, memory is manually managed, so even
|
||||
uninitialized memory is already a 'valid object'. So
|
||||
we can call commit immediately.) */
|
||||
} while (! mps_commit(ApDemo, p, cbBuffer));
|
||||
|
||||
report("Allocated 100 bytes", ArenaDemo, PoolDemo);
|
||||
report("Allocated 256 bytes", ArenaDemo, PoolDemo);
|
||||
|
||||
{
|
||||
/* Show that it really is memory */
|
||||
|
|
@ -137,7 +156,8 @@ int main(void)
|
|||
|
||||
printf(
|
||||
"Success: The hello-world example code successfully allocated\n"
|
||||
"some memory using mps_alloc(), in an LO pool, in a VM arena.\n"
|
||||
"some memory using an allocation point with\n"
|
||||
"mps_reserve()..mps_commit(), in an LO pool, in a VM arena.\n"
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue