# Stable structures: Bounded vs Unbounded

**URL:** <https://forum.dfinity.org/t/stable-structures-bounded-vs-unbounded/40035>\
**Category:** Rust\
**Created:** [January 13, 2025, 3:47pm UTC](https://forum.dfinity.org/t/stable-structures-bounded-vs-unbounded/40035 "2025-01-13T15:47:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![barolukluk](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@barolukluk](https://forum.dfinity.org/u/barolukluk)\
**Post date:** [January 13, 2025, 3:47pm UTC](https://forum.dfinity.org/t/stable-structures-bounded-vs-unbounded/40035/1 "2025-01-13T15:47:46Z")

</div>

I have a data canister that uses the stable region of memory. I am using a `StableBTreeMap` to store my assets by key & value pairs. When I use the `Bound::Bounded` type and set the MAX\_SIZE value, I am able to store more than 4GB of data in the canister. However, when I try to use the `Bound::Unbounded` type, the canister stops storing new data when the canister state reaches 4GB and throws the following error:

```auto
"IC0503: Error from canister pmm6l-wiaaa-aaaae-aakfq-cai: Canister called `ic0.trap` with message: Used bytes limit reached 4001281850 >= 4000000000.\\\\nConsider gracefully handling errors from this canister or modifying the canister to handle exceptions. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly\\\")', hugemap_index/src/helpers.rs:201:18.\\nConsider gracefully handling failures from this canister or modifying the canister to handle exceptions. See the documentation: http://internetcomputer.org/docs/current/references/execution-errors#trapped-explicitly\"

```

If I have to use the Bound::Bounded type to use the stable memory, I can always create new maps to store different sizes of values to not waste memory, but do I have to?

Here’s the the declaration of the corresponding struct:

```auto
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ValStable(pub Vec<u8>);

impl Storable for ValStable {
    const BOUND: ic_stable_structures::storable::Bound =
        ic_stable_structures::storable::Bound::Unbounded;
    fn to_bytes(&self) -> Cow<[u8]> {
        Cow::Borrowed(&self.0)
    }

    fn from_bytes(bytes: Cow<[u8]>) -> Self {
        ValStable(bytes.to_vec())
    }
}

impl ValStable {
    pub fn new(data: Vec<u8>) -> Self {
        ValStable(data)
    }
}

```

By the way, my canisters are deployed in the subnet: “shefu-t3kr5-t5q3w-mqmdq-jabyv-vyvtf-cyyey-3kmo4-toyln-emubw-4qe”. I added this detail in case the issue is related to the subnet where my canisters are deployed.
