273 |
return pool_malloc (pool, amt); |
return pool_malloc (pool, amt); |
274 |
} |
} |
275 |
|
|
276 |
|
/* Allocates a memory region N * S bytes in size from POOL and |
277 |
|
returns a pointer to the region's start. |
278 |
|
N must be nonnegative, S must be positive. |
279 |
|
Terminates the program if the memory cannot be obtained, |
280 |
|
including the case where N * S overflows the range of size_t. */ |
281 |
|
void * |
282 |
|
pool_nalloc (struct pool *pool, size_t n, size_t s) |
283 |
|
{ |
284 |
|
if (xalloc_oversized (n, s)) |
285 |
|
xalloc_die (); |
286 |
|
return pool_alloc (pool, n * s); |
287 |
|
} |
288 |
|
|
289 |
/* Allocates SIZE bytes in POOL, copies BUFFER into it, and |
/* Allocates SIZE bytes in POOL, copies BUFFER into it, and |
290 |
returns the new copy. */ |
returns the new copy. */ |
291 |
void * |
void * |
368 |
return xmalloc (amt); |
return xmalloc (amt); |
369 |
} |
} |
370 |
|
|
371 |
|
/* Allocates and returns N elements of S bytes each, to be |
372 |
|
managed by POOL. |
373 |
|
If POOL is a null pointer, then allocates a normal memory block |
374 |
|
with malloc(). |
375 |
|
N must be nonnegative, S must be positive. |
376 |
|
Terminates the program if the memory cannot be obtained, |
377 |
|
including the case where N * S overflows the range of size_t. */ |
378 |
|
void * |
379 |
|
pool_nmalloc (struct pool *pool, size_t n, size_t s) |
380 |
|
{ |
381 |
|
if (xalloc_oversized (n, s)) |
382 |
|
xalloc_die (); |
383 |
|
return pool_malloc (pool, n * s); |
384 |
|
} |
385 |
|
|
386 |
/* Changes the allocation size of the specified memory block P managed |
/* Changes the allocation size of the specified memory block P managed |
387 |
by POOL to AMT bytes and returns a pointer to the beginning of the |
by POOL to AMT bytes and returns a pointer to the beginning of the |
388 |
block. |
block. |
424 |
return xrealloc (p, amt); |
return xrealloc (p, amt); |
425 |
} |
} |
426 |
|
|
427 |
|
/* Changes the allocation size of the specified memory block P |
428 |
|
managed by POOL to N * S bytes and returns a pointer to the |
429 |
|
beginning of the block. |
430 |
|
N must be nonnegative, S must be positive. |
431 |
|
If POOL is a null pointer, then the block is reallocated in |
432 |
|
the usual way with xrealloc(). |
433 |
|
Terminates the program if the memory cannot be obtained, |
434 |
|
including the case where N * S overflows the range of size_t. */ |
435 |
|
void * |
436 |
|
pool_nrealloc (struct pool *pool, void *p, size_t n, size_t s) |
437 |
|
{ |
438 |
|
if (xalloc_oversized (n, s)) |
439 |
|
xalloc_die (); |
440 |
|
return pool_realloc (pool, p, n * s); |
441 |
|
} |
442 |
|
|
443 |
/* Frees block P managed by POOL. |
/* Frees block P managed by POOL. |
444 |
If POOL is a null pointer, then the block is freed as usual with |
If POOL is a null pointer, then the block is freed as usual with |
445 |
free(). */ |
free(). */ |