Skip to content

Commit

Permalink
fix: final review
Browse files Browse the repository at this point in the history
  • Loading branch information
X committed Aug 8, 2024
1 parent d4c0c96 commit 9419190
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 76 deletions.
6 changes: 4 additions & 2 deletions src/backend/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ pub fn heap_to_stable(state: &mut State) {
let offset = 16; // start of the heap
let bytes = serde_cbor::to_vec(&state).expect("couldn't serialize the state");
let len = bytes.len() as u64;
if offset + len > (stable64_size() << 16) {
stable64_grow((len >> 16) + 1).expect("couldn't grow memory");
let stable_mem_size_bytes = stable64_size() << 16;
let new_pages = (offset + len).saturating_sub(stable_mem_size_bytes) >> 16;
if new_pages > 0 {
stable64_grow(new_pages + 1).expect("couldn't grow memory");
}
stable64_write(offset, &bytes);
stable64_write(0, &offset.to_be_bytes());
Expand Down
Loading

0 comments on commit 9419190

Please sign in to comment.