> ## Documentation Index
> Fetch the complete documentation index at: https://iso8583sim.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Pool

> Object pooling for high-throughput ISO8583 message processing.

`iso8583sim.core.pool`

## `MessagePool`

```python theme={null}
MessagePool(size: int = 100)
```

Thread-safe object pool for ISO8583Message instances.

Using a pool reduces object allocation overhead in high-throughput
scenarios by reusing message objects instead of creating new ones.

<Note>
  pool = MessagePool(size=100)

  # Get a message from the pool

  msg = pool.acquire("0100", \{2: "4111111111111111"})

  # Process the message...

  # Return it to the pool when done

  pool.release(msg)
</Note>

Note: Messages returned to the pool have their fields cleared,
so don't hold references to field data after releasing.

Initialize the message pool.

**Parameters**

<ResponseField name="size" type="int" default="100">
  Maximum number of messages to keep in the pool
</ResponseField>

### `acquire()`

```python theme={null}
def acquire(
    mti: str,
    fields: dict[int, str],
    version: ISO8583Version = ISO8583Version.V1987,
    network: CardNetwork | None = None,
    raw_message: str | None = None,
    bitmap: str | None = None,
) -> ISO8583Message
```

Get a message from the pool or create a new one.

**Parameters**

<ResponseField name="mti" type="str" required>
  Message Type Indicator
</ResponseField>

<ResponseField name="fields" type="dict[int, str]" required>
  Message fields dictionary
</ResponseField>

<ResponseField name="version" type="ISO8583Version" default="ISO8583Version.V1987">
  ISO8583 version
</ResponseField>

<ResponseField name="network" type="CardNetwork | None" default="None">
  Card network
</ResponseField>

<ResponseField name="raw_message" type="str | None" default="None">
  Original raw message string
</ResponseField>

<ResponseField name="bitmap" type="str | None" default="None">
  Message bitmap
</ResponseField>

<ResponseField name="Returns" type="ISO8583Message">
  An ISO8583Message instance (either recycled or new)
</ResponseField>

### `release()`

```python theme={null}
def release(msg: ISO8583Message) -> None
```

Return a message to the pool for reuse.

**Parameters**

<ResponseField name="msg" type="ISO8583Message" required>
  The message to return to the pool
</ResponseField>

Note: The message's fields are cleared to avoid holding
references to old data.

### `clear()`

```python theme={null}
def clear() -> None
```

Clear all messages from the pool.

### `size`

Get current number of messages in the pool.

### `max_size`

Get maximum pool size.

## Functions

### `get_default_pool()`

```python theme={null}
def get_default_pool(size: int = 100) -> MessagePool
```

Get or create the default global message pool.

**Parameters**

<ResponseField name="size" type="int" default="100">
  Pool size (only used on first call)
</ResponseField>

<ResponseField name="Returns" type="MessagePool">
  The default MessagePool instance
</ResponseField>

### `reset_default_pool()`

```python theme={null}
def reset_default_pool() -> None
```

Reset the default global pool.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.