So , not to bug you , but my 2 cents again. So in trying to understand how memory allocation and deallocation works in certain technologies, I got my hands soiled in rust. So rust does something interesting with Strings - and other data types that are stored on the heap. So in most languages I know , strings are references - they point to somewhere in memory. What happens when you've got two variables pointing to the same location and they are ready to clear their memory after they go out of scope¿ Do they clear the same memory¿ This will cause memory issues.. What rust does is , rust is like " look s1, I know you were first to point to this location, but s2 wants to help you do that so you know what s1, you can go home. Let s2 handle it ". So at any point in time , only one item is pointing to somewhere in memory( usually the heap ). This helps memory management a great deal. Please note: this is spoken in reference to values stored on the heap . Memory management in stacks are fairly straightforward.. my 2 cents; might not be the most accurate 2 cents..
Arthur Chima’s Post
More Relevant Posts
-
🦀Rust's Stack and Heap: A Quick Dive 💻 In Rust, memory management is a fascinating journey that involves two main areas: the stack and the heap. 🌐 📚 Stack: Every function call in Rust has its own dedicated space on the stack, a region of memory that's fast but limited in size. Here, data follows a Last-In, First-Out (LIFO) structure. Variables with known, fixed sizes, and lifetimes are typically stored on the stack. It's efficient and straightforward but comes with limitations. 💡 Heap: For dynamic, unknown-size data or data that needs to persist beyond the scope of a function, Rust turns to the heap. The heap is a region of memory that is more flexible but requires explicit allocation and deallocation. Ownership rules, enforced by Rust's borrow checker, ensure that memory is handled safely and efficiently.
To view or add a comment, sign in
-
Day 0x02 🌱 Went over Chapter 1 (Already familiar with most of the concepts presented). Topics covered: The Static allocation, stack, pointers, heaps, manual & automatic memory management(Allocator, Mutator & Collector), Approaches to automatic memory management eg Reference counting & Tracking collector. The stack machine is a very important concept to how modern day languages like .NET run code. Using the stack machine enables designing platform independent VMs eg. JVM, .NET Runtime. Pointers are deadly, pointers allow us build complex data structures. Heap: The heap is an area of memory used for dynamically allocated objects. Some comparisons between the stack and heap(Picture below). Manual Memory Management: "With great power comes great responsibility". The developer is solely responsible for allocating and deallocating memory. Memory leaks can happen, errors due to dereferencing a NULL pointer, casting can be error prone etc Manual memory management can be cumbersome, Automatic memory management to the rescue. The process is called Garbage Collection. 🛠 Happy Learning!! ✔ #100daysoflearning #softwareengineering #dotnet 🚀
To view or add a comment, sign in
-
Most devs despair when they have to deal with a tangle mess of an application consisting of dozens if not hundreds of moving pieces. Do you know there are actual principles to solve such situation? Check out my article, it will only take you a couple of minutes: https://lnkd.in/djM4z2Yz
To view or add a comment, sign in
-
Since you're never gonna get it right the first time, when writing a query. How you write a query will impact how you have to go back to create an Index. An index is just an optimization around a query. https://lnkd.in/d7XmTPtF
Learning Season - API Design in 2023 - Handlers, DB Schema & Indexes
https://www.youtube.com/
To view or add a comment, sign in
-
What happens when a value is moved in #Rust and ownership is transferred? Is the moved value destroyed from the previous #memory location? The #data is not actually destroyed on move. The screenshot shows a simple #code snippet where the string "hello" is stored on the #heap and then ownership of the data is transferred to the variable y. We take an immutable raw #pointer to x and dereference it to see if the string "hello" is still stored in that memory location. When you run the code you'd see the output "Location x still holds hello: true". https://lnkd.in/dDraqjXM What really happens is that the #compiler keeps track of data it has moved but it doesn't destroy the data in the location, instead it knows that the data in that location is invalid and it can at anytime overwrite it if it needs the space. This is one of the reasons why #dereferencing a pointer is unsafe. It's possible that at the time x_ptr is being #dereferenced the compiler could have written something else to the location.
To view or add a comment, sign in
-
Every Way To Get Structured Output From LLMs https://lnkd.in/ep-GTysT
Every Way To Get Structured Output From LLMs
boundaryml.com
To view or add a comment, sign in
-
Lazy evaluation in PySpark Lazy evaluation in PySpark is a feature that defers the execution of operations until they are absolutely necessary, optimizing performance by reducing the amount of data processed. For more info watch the video: https://lnkd.in/gFMKq4CY
What is Lazy Evaluation in Spark? | IN 3 MINUTES | Definition | Applications
https://www.youtube.com/
To view or add a comment, sign in
-
This code is part of my Data Structures learning, where I implemented a stack using a linked list in C. It supports the following stack operations: Push an element onto the stack. Pop an element from the stack. Print the current elements of the stack. Peek at the top element of the stack. Check the number of elements in the stack. The implementation uses dynamic memory allocation, making the stack grow and shrink as needed. source of code https://lnkd.in/d9MrDjfk
To view or add a comment, sign in
-
Algorithm efficiency, performance, scalability... Big O Notation offers a helpful lens into understanding how your code performs and scales. I wrote this concise article explaining it with simple examples. Hope it helps! (Portuguese version in my dev.to profile)
Big O Notation
dev.to
To view or add a comment, sign in