# Fast way to zeroize stable memory?

**URL:** <https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649>\
**Category:** Developers\
**Created:** [November 17, 2022, 2:50pm UTC](https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649 "2022-11-17T14:50:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![senior.joinu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/senior.joinu/32/9240_2.png) [@senior.joinu](https://forum.dfinity.org/u/senior.joinu)\
**Post date:** [November 17, 2022, 2:50pm UTC](https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649/1 "2022-11-17T14:50:10Z")

</div>

I was wondering if it is possible to add system API to zeroize 64-bit stable memory?  
Something like `stable64_zeroize(pages_offset, pages_count)`.

I’m working on stable collections in `ic-stable-memory` and for now some of these collections are limited in size because of that. For example a `SHashMap` requires you to zeroize the whole block of memory, before using it and right now I’m doing it by creating a cleaning vector `vec![0u8; SIZE]` and writing it into the desired position in stable memory which is both: expensive and limited (since I can’t create a `Vec` bigger than 4GBs). So the maximum size of a `SHashMap` is also limited to 4GBs.

There is a workaround - you can write this cleaning vector multiple times to different locations, but I’m afraid this would simply make a canister hit message limit. I believe there should be a lower level (and much cheaper) API to physically discharge bits to zeros that can be exposed through IC’s API, but maybe I’m wrong.

---

<div class="post-metadata">

**Author:** ![ggreif](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ggreif/32/301_2.png) [@ggreif](https://forum.dfinity.org/u/ggreif)\
**Post date:** [November 17, 2022, 5:55pm UTC](https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649/2 "2022-11-17T17:55:46Z")

</div>

Look into Wasm bulk memory operations. The replica should accept them, but your SDK may have trouble generating those bytecodes. Which language are you interested in?

---

<div class="post-metadata">

**Author:** ![senior.joinu](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/senior.joinu/32/9240_2.png) [@senior.joinu](https://forum.dfinity.org/u/senior.joinu)\
**Post date:** [November 17, 2022, 5:57pm UTC](https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649/3 "2022-11-17T17:57:14Z")

</div>

Are these bulk operations exposed?

I’m from team rust.

---

<div class="post-metadata">

**Author:** ![Aaron.Walsh](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/aaron.walsh/32/8151_2.png) [@Aaron.Walsh](https://forum.dfinity.org/u/Aaron.Walsh)\
**Post date:** [November 19, 2022, 2:25am UTC](https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649/4 "2022-11-19T02:25:34Z")

</div>

I am particularly interested in the type of collections you are building?

---

<div class="post-metadata">

**Author:** ![AdamS](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/adams/32/5248_2.png) [@AdamS](https://forum.dfinity.org/u/AdamS)\
**Post date:** [November 19, 2022, 5:06am UTC](https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649/6 "2022-11-19T05:06:36Z")

</div>

Stable memory can only be interacted via functions; it’s not exposed as a wasm memory and so wasm bulk memory operations can’t touch it to my knowledge.

---

<div class="post-metadata">

**Author:** ![ggreif](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/ggreif/32/301_2.png) [@ggreif](https://forum.dfinity.org/u/ggreif)\
**Post date:** [November 19, 2022, 8:58am UTC](https://forum.dfinity.org/t/fast-way-to-zeroize-stable-memory/16649/7 "2022-11-19T08:58:57Z")

</div>

Ooops, you are right. I missed the “stable memory” part. But not all is lost! @senior.joinu feel free to lobby for (stable memory) system call API equivalents of Wasm bulk memory instructions.

EDIT: I searched and finally found it…  
This is the thread where you can voice your wish: [Improving the utility of stable memory - #3 by johan](https://forum.dfinity.org/t/improving-the-utility-of-stable-memory/16210/3)
