# Memcpy a struct in storage\_var

**URL:** <https://community.starknet.io/t/memcpy-a-struct-in-storage-var/1877>\
**Category:** Starknet Technical Development\
**Created:** [July 26, 2022, 11:23pm UTC](https://community.starknet.io/t/memcpy-a-struct-in-storage-var/1877 "2022-07-26T23:23:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bowlofchilli](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/bowlofchilli/32/73368_2.png) [@bowlofchilli](https://community.starknet.io/u/bowlofchilli)\
**Post date:** [July 26, 2022, 11:23pm UTC](https://community.starknet.io/t/memcpy-a-struct-in-storage-var/1877/1 "2022-07-26T23:23:08Z")

</div>

let (result : ERC721PUT\*) = alloc()  
let (local \_bid : ERC721PUT) = bids.read(bid\_index)  
memcpy(result, &\_bid, ERC721PUT.SIZE) curious why this will not work? is &\_bid not appropriate here ?

bids is a storage\_var

I get this \nUnknown value for memory cell at address 12:12.\n assert [frame.dst] = [frame.src]\n

---

<div class="post-metadata">

**Author:** ![gaetbout](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/gaetbout/32/712_2.png) [@gaetbout](https://community.starknet.io/u/gaetbout)\
**Post date:** [July 27, 2022, 9:52am UTC](https://community.starknet.io/t/memcpy-a-struct-in-storage-var/1877/2 "2022-07-27T09:52:01Z")

</div>

Last time I had this error it was linked to the fact that the size was uncorrect.  
I think this question would be answered more quickly on the discord 🙂

---

<div class="post-metadata">

**Author:** ![bowlofchilli](https://dub1.discourse-cdn.com/flex005/user_avatar/community.starknet.io/bowlofchilli/32/73368_2.png) [@bowlofchilli](https://community.starknet.io/u/bowlofchilli)\
**Post date:** [July 27, 2022, 2:37pm UTC](https://community.starknet.io/t/memcpy-a-struct-in-storage-var/1877/3 "2022-07-27T14:37:48Z")

</div>

Just to complete the circle for anybody else. I was returning from a function the array where the result\_len was based on felt and not on ERC721PUT

return (result\_len, result) ← result\_len was the problem.

Thanks Gaetbout

---

<div class="post-metadata">

**Author:** ![hacxx](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@hacxx](https://community.starknet.io/u/hacxx)\
**Post date:** [June 26, 2025, 8:34am UTC](https://community.starknet.io/t/memcpy-a-struct-in-storage-var/1877/4 "2025-06-26T08:34:27Z")

</div>

This doesn’t work because `&_bid` refers to a local variable in memory, not a storage reference. `bids.read(bid_index)` loads the value into memory, but `memcpy` expects both source and destination to be valid memory addresses. `_bid` is a value, not a pointer. You can’t take its address like that. Instead, write each field manually or load directly into `result`.
