Pooled memory allocation for legacy model objects.
More...
#include <stdlib.h>
#include "mempool.h"
|
| alloc_handle_t * | AllocInit () |
| | Create a pool and select it as the shared current allocation pool.
|
| |
| char * | Alloc (long size) |
| | Reserve four-byte-aligned storage from the current pool.
|
| |
| alloc_handle_t * | AllocSetPool (alloc_handle_t *newpool) |
| | Replace the shared current-pool selection without freeing either pool.
|
| |
| void | AllocReset () |
| | Rewind the current pool for reuse without releasing its blocks.
|
| |
| void | AllocFreePool () |
| | Free every block/header and the root of the shared current pool.
|
| |
Pooled memory allocation for legacy model objects.
- Author
- Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com (OpenSWMM maintenance and extensions)
- Copyright
- Copyright (c) 2026 Caleb Buahin. OpenSWMM contributions only; original EPA SWMM credits are retained.
- License
- Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.
◆ ALLOC_BLOCK_SIZE
| #define ALLOC_BLOCK_SIZE 64000 /*(62*1024)*/ |
◆ alloc_hdr_t
◆ alloc_root_t
◆ Alloc()
| char * Alloc |
( |
long | size | ) |
|
Reserve four-byte-aligned storage from the current pool.
- Parameters
-
| [in] | size | Nonnegative byte count small enough to fit within one ALLOC_BLOCK_SIZE block after four-byte rounding; oversized requests are unchecked. |
- Returns
- Borrowed pointer into pool storage, or NULL if allocating another block fails. Zero-byte requests need not return distinct pointers.
- Precondition
- AllocInit() succeeded and a live pool is current. Returned storage must not be freed individually and is valid only until pool reset/free.
- Note
- Rounds using the legacy 32-bit alignment mask; callers must not request over-aligned C++ objects or sizes outside its representable range.
◆ AllocFreePool()
| void AllocFreePool |
( |
void | | ) |
|
Free every block/header and the root of the shared current pool.
- Precondition
- A live non-null pool is current and no outstanding allocations are in use.
- Postcondition
- All pointers into this pool become invalid and shared root becomes NULL. Does not free any separately owned pools that are not currently selected.
◆ AllocInit()
Create a pool and select it as the shared current allocation pool.
- Returns
- Owned pool handle, or NULL if root/first-block allocation fails.
- Postcondition
- Replaces the shared root pointer; a successful pool is released by selecting it and calling AllocFreePool(). Existing pools are not freed.
- Note
- Failure may leave a partial root allocation; allocation calls are not thread-safe.
◆ AllocReset()
Rewind the current pool for reuse without releasing its blocks.
- Precondition
- A live pool is selected by AllocInit()/AllocSetPool().
- Postcondition
- Existing allocation contents may be overwritten by later Alloc() calls; callers must discard outstanding object pointers before reuse.
◆ AllocSetPool()
Replace the shared current-pool selection without freeing either pool.
- Parameters
-
| [in] | newpool | Existing pool handle; NULL deselects a pool but cannot be followed by allocation/reset/free until a live pool is selected. |
- Returns
- Previous pool handle, possibly NULL. Ownership is unchanged.