Archishman Sengupta’s Post

View profile for Archishman Sengupta, graphic

SDE - 1 Fullstack @StackWealth (YC S21) | ICPC Regionalist | 3x YC dev

Rust has one of the best memory management & it does not need a garbage collector. - rust has a concept of ‘ownership’ and ‘borrow checker’. - these prevent null pointer dereferencing, dangling pointers, and data races at compile time, without needing a garbage collection. for an example, take this java stack + heap trace: public class mainclass {  public static void main(string[] args){   int[] archie = new int[10];   int[] archie2 = archie;  } } for this java stacktrace (pic 1): - archie2 references the same heap data as archie, so if archie goes out of scope, archie2 still references the heap. - The GC won't deallocate the heap data while archie2 is in use. - Once archie2 goes out of scope, the GC cleans up the heap. For rust (pic 2, 3): - At L3, `archie2=archie` is a 'move', transferring ownership from archie to archie2. - So when we move from archie to archie2, the data that was owned by archie is now owned by archie2 - Since archie doesn’t own any data, it is uninitialized after L2 is executed, so L2 would be popped off of the stack. This is how rust's ownership model prevents common MM issues at compile time without needing a GC. #java #rust #NoFluffEngineering

  • No alternative text description for this image
Archishman Sengupta

SDE - 1 Fullstack @StackWealth (YC S21) | ICPC Regionalist | 3x YC dev

5d

To view or add a comment, sign in

Explore topics