Stream: beginners

Topic: ✔ Memory of RocList vs RocArray?


view this post on Zulip Shaiden Spreitzer (Dec 05 2023 at 09:58):

I'm a bit confused about what a RocList is supposed to represent. A quick glance at the implementation seems to indicate it's a flat (heap) array. So with a List U32 can I assume that I get a single contiguous chunk of memory? Or do I get a "linked list" with pointers to individual U32s?
What if I have a List BigBooba, do I get an array of pointers, or a linked list of Boobas or are all Boobas on the heap next to each other?
Would a RocArray guarantee memory adjacency or does RocList already come with such a guarantee ???
Sorry for all the questions, I'm new to Roc!!

view this post on Zulip Luke Boswell (Dec 05 2023 at 10:02):

I find the zig builtin implementation easier to understand https://github.com/roc-lang/roc/blob/main/crates/compiler/builtins/bitcode/src/list.zig

view this post on Zulip Luke Boswell (Dec 05 2023 at 10:04):

Single contiguous chnk of memory I think is the answer.

view this post on Zulip Shaiden Spreitzer (Dec 05 2023 at 10:05):

Luke Boswell said:

I find the zig builtin implementation easier to understand https://github.com/roc-lang/roc/blob/main/crates/compiler/builtins/bitcode/src/list.zig

I also came across this https://github.com/roc-lang/roc/blob/main/crates/roc_std/src/roc_list.rs
Are these equivalent?

view this post on Zulip Luke Boswell (Dec 05 2023 at 10:07):

Presumably I guess. I'm not really familiar with this, but the compiler is in Rust using that crate, and the builtins are in Zig using the zig module. And the talk to each other no issue.

view this post on Zulip Brendan Hansknecht (Dec 05 2023 at 16:07):

They should be equivalent, but the rust version is more likely to be buggy, out or date, or wrong in places. I also, think the zig version is a lot more direct and easy to understand

view this post on Zulip Brendan Hansknecht (Dec 05 2023 at 16:07):

Anyway, yeah our RocList is really like a C++ vector or Java ArrayList.

view this post on Zulip Notification Bot (Dec 05 2023 at 16:15):

Shaiden Spreitzer has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC