# If I am to implement a continuous memory data structure like arrays or vectors in Scheme

**URL:** <https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431>\
**Category:** Questions & Answers\
**Created:** [December 19, 2024, 5:37am UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431 "2024-12-19T05:37:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![YongaTechnic](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/yongatechnic/32/2109_2.png) [@YongaTechnic](https://racket.discourse.group/u/YongaTechnic)\
**Post date:** [December 19, 2024, 5:37am UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431/1 "2024-12-19T05:37:04Z")

</div>

Hi,

How can someone allocate a continuous memory in scheme, and implement a vector like data structure with O(1) access without using lists in Scheme?

Thanks

---

<div class="post-metadata">

**Author:** ![YongaTechnic](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/yongatechnic/32/2109_2.png) [@YongaTechnic](https://racket.discourse.group/u/YongaTechnic)\
**Post date:** [December 19, 2024, 5:41am UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431/2 "2024-12-19T05:41:32Z")

</div>

I don't want to depend on a low level C library, Can it be done with cons and box?  
Or may be a different idea?

---

<div class="post-metadata">

**Author:** ![gus-massa](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/gus-massa/32/507_2.png) [@gus-massa](https://racket.discourse.group/u/gus-massa)\
**Post date:** [December 19, 2024, 12:59pm UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431/3 "2024-12-19T12:59:36Z")

</div>

I don't understand your question. You can use  
[4.12&nbsp;Vectors](https://docs.racket-lang.org/reference/vectors.html) to store arbitrary things like in a `list`, or use [4.5&nbsp;Byte Strings](https://docs.racket-lang.org/reference/bytestrings.html) for more raw stuff.

Some curses, teach only `cons` to simplify the technical part and for pedagogical reasons, but most Scheme implementations have other constructions to be more efficient.

---

<div class="post-metadata">

**Author:** ![YongaTechnic](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/yongatechnic/32/2109_2.png) [@YongaTechnic](https://racket.discourse.group/u/YongaTechnic)\
**Post date:** [December 19, 2024, 3:22pm UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431/4 "2024-12-19T15:22:58Z")

</div>

Vectors under the hood, use C library right? How is it implemented?

---

<div class="post-metadata">

**Author:** ![hendrikboom3](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/hendrikboom3/32/2748_2.png) [@hendrikboom3](https://racket.discourse.group/u/hendrikboom3)\
**Post date:** [December 19, 2024, 4:24pm UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431/5 "2024-12-19T16:24:05Z")

</div>

Go far enough under the hood, you'll find everything uses C or assembler or equivalent.

-- hendrik

---

<div class="post-metadata">

**Author:** ![samth](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/samth/32/3_2.png) [@samth](https://racket.discourse.group/u/samth)\
**Post date:** [December 19, 2024, 4:48pm UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431/6 "2024-12-19T16:48:05Z")

</div>

Vectors are implemented in a collection of built-in functions and the code generated by the compiler, but they are similar to C arrays in memory representation.

---

<div class="post-metadata">

**Author:** ![hendrikboom3](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/hendrikboom3/32/2748_2.png) [@hendrikboom3](https://racket.discourse.group/u/hendrikboom3)\
**Post date:** [December 19, 2024, 5:43pm UTC](https://racket.discourse.group/t/if-i-am-to-implement-a-continuous-memory-data-structure-like-arrays-or-vectors-in-scheme/3431/7 "2024-12-19T17:43:34Z")

</div>

but they are similar to C arrays in memory representation.

I'm presuming that the compiler generates actual machine intructions for the vector operatarions,  
so it's operating at a slightly lower level than either C or assembler.

But for considerations of efficiency this get down to worrying about hardware latency  
and effectively umpredictable picosecond delays.

There is a point in low-level language implementation where it is hardy worth investigating further.

-- hendrik
