OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
mempool.h File Reference

Pooled memory allocation for legacy model objects. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  alloc_handle_t
 

Functions

alloc_handle_t * AllocInit (void)
 Create a pool and select it as the shared current allocation pool.
 
char * Alloc (long)
 Reserve four-byte-aligned storage from the current pool.
 
alloc_handle_t * AllocSetPool (alloc_handle_t *)
 Replace the shared current-pool selection without freeing either pool.
 
void AllocReset (void)
 Rewind the current pool for reuse without releasing its blocks.
 
void AllocFreePool (void)
 Free every block/header and the root of the shared current pool.
 

Detailed Description

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)
License
Apache-2.0 for OpenSWMM contributions; original EPA SWMM provenance is retained.

Function Documentation

◆ Alloc()

char * Alloc ( long size)

Reserve four-byte-aligned storage from the current pool.

Parameters
[in]sizeNonnegative 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.
Here is the caller graph for this function:

◆ 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()

alloc_handle_t * AllocInit ( void )

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()

void AllocReset ( void )

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()

alloc_handle_t * AllocSetPool ( alloc_handle_t * newpool)

Replace the shared current-pool selection without freeing either pool.

Parameters
[in]newpoolExisting 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.