2023-03-22
2084
#rust
Yashodhan Joshi
163607
109
Mar 22, 2023 â‹… 7 min read

Using Cow in Rust for efficient memory utilization

Yashodhan Joshi I am a student interested in physics and systems programming currently exploring Rust and operating systems. I am also passionate about helping others learn.

Recent posts:

Rust logo over black marble background.

Handling memory leaks in Rust

Learn how to manage memory leaks in Rust, avoid unsafe behavior, and use tools like weak references to ensure efficient programs.

Ukeje Goodness
Nov 20, 2024 â‹… 4 min read
Robot pretending to be a person.

Using curl-impersonate in Node.js to avoid blocks

Bypass anti-bot measures in Node.js with curl-impersonate. Learn how it mimics browsers to overcome bot detection for web scraping.

Antonello Zanini
Nov 20, 2024 â‹… 13 min read
Solving Eventual Consistency In Frontend

Solving eventual consistency in frontend

Handle frontend data discrepancies with eventual consistency using WebSockets, Docker Compose, and practical code examples.

Kayode Adeniyi
Nov 19, 2024 â‹… 6 min read
How To Use Lazy Initialization Pattern With Rust 1.80

How to use the lazy initialization pattern with Rust 1.80

Efficient initializing is crucial to smooth-running websites. One way to optimize that process is through lazy initialization in Rust 1.80.

Yashodhan Joshi
Nov 18, 2024 â‹… 5 min read
View all posts

3 Replies to "Using Cow in Rust for efficient memory utilization"

  1. I really enjoyed your post. It really helped understand the problem well.
    I think there is a small bug, it doesn’t distract much from the value of the post, but it’s always nice if the code works. The first example is missing `seen_ids.insert(element.id.clone());`, or something of the sort when looping through the list to track if an id has been seen. The second code snippet has the HashSet insert.

    1. Hey Marc, thanks a lot for noticing and reporting this! The first example was initially supposed to be just a pseudo-code / algorithm, and then the proper code was supposed to be the second snippet. However, While writing and re-writing, I slipped in some code in the first, and the final version had the missing code line that you noticed. In any case I should have taken more care.
      Thanks a lot for commenting this, I have fixed the error now. Hope you found this post useful and fun to read!

  2. Consider a search and replace program that searches for a particular text and if found, replaces it with another text in a UTF-8 encoded text file. Most of the time, the text file contains none or only a few occurrences of the search text. As the program parses each line in the text file, only if the search text is found, that line should be mutated. Otherwise no need to mutate that line. Cow is perfectly suitable for this use case.

Leave a Reply