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
Archishman Sengupta’s Post
More Relevant Posts
-
Created a Library Book Catalogue terminal-based project using Binary Search Trees and arrays to put my data structures learnings into practice! Used BST to allow efficient searching and adding of books according to the year of publication. Plus, use of arrays allowed me to hold multiple book objects in a particular year. Check out the source code on https://lnkd.in/gzYMw7gG #DSA #Java #OOP #BST #Arrays
To view or add a comment, sign in
-
Arrow has two components: (1) specifications (2) implementations The most well-known specification is the "Arrow Columnar Format". Another specification is "Arrow Database Connectivity" (ADBC). Implementations are libraries to work with the Arrow format: - read external disk format (e.g. Parquet) into Arrow in-memory format - transform Arrow data in memory - write in-memory Arrow format to external disk format - … Implementations can be "official" and "unofficial": - official ➜ part of Apache Arrow project - unofficial ➜ maintained by third party Official implementations exist in many languages: - C++ - Java - Rust - Python (wrapper around C++) - … `polars-arrow` is an example of an unofficial Arrow implementation. It's a "trimmed down implementation of the Arrow spec and is tuned for Polars’ needs". polars-arrow is a fork of `Arrow2`. Arrow2 is a (no longer maintained) rewrite of the official Rust implementation of Arrow. Arrow2 was built to improve upon the official implementation, for example in terms of speed. #dataengineering #softwareengineering
To view or add a comment, sign in
-
Day 36 of #solving LeetCode 75 [ q- 39 ] Binary Tree Right Side View Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example 1: Input: root = [1,2,3,null,5,null,4] Output: [1,3,4] Example 2: Input: root = [1,null,3] Output: [1,3] Example 3: Input: root = [] Output: [] Constraints: The number of nodes in the tree is in the range [0, 100]. -100 <= Node.val <= 100 Solution: In a java class 1. Initializes a list to store the values of nodes seen from the right side and call the right method to traverse the tree. 2. Create a method to traverse the binary tree recursively in a depth-first manner. which takes three parameters: the current node root, the current level level, and the list list to store the right side view. 3. If the root is null, indicating that the traversal has reached the end of a branch, return. 4. If the current level is greater than maxLevel, it means that the current node is the rightmost node seen at that level so far. add the value of the current node to the list, and update maxLevel to current level. 5. Call the method recursively for the right child of the current node (root.right) with the incremented level (level+1) and the same list. 6. Call the method recursively for the left child of the current node (root.left) with the incremented level (level+1) and the same list. 7. As the traversal progresses, the list will contain the values of nodes seen from the right side at each level. 8. Finally, return the list containing the right side view of the binary tree. #timecomplexity : The time complexity of this method is O(n), this is because each node is visited exactly once during the traversal. #spacecomplexity : The space complexity is also O(n) in the worst case, this is due to the recursive calls on the call stack, which can go up to the height of the binary tree. #java #javadevelopers #dsa #leetcode #problemsolving
To view or add a comment, sign in
-
Day-2☀️ On Day-2 , Complete the basic of Arrays. Arrays are fundamental data structures in Java that allow you to store and manipulate a fixed-size collection of elements of the same type. Declaration- To declare an array in Java, you specify the data type followed by square brackets and the array name. “int[] myArray;” Why We Use Arrays? •-Efficiency: Arrays provide fast access to elements due to their fixed size and contiguous memory allocation. •-Simplicity: Arrays are straightforward and easy to use, making them ideal for basic data storage needs. Thanks to @Ashok Soni Sir , @Tosscall Services,@Vemu Jyoti Rao Sir for Their Guidance #GlistataSoftwarwSolutions #TossCall Service #SEEDIT Solution #Java#KeepCoding🚀 Here are some related questions of Array:- -{Enter no to be search} -{Find the Largest no in list} -{Sum of three no. In row } -{Write the Running Sum of elements} -{Write the Running Addition of Colours} Solutions 👇🏻👇🏻
To view or add a comment, sign in
-
Have you ever wondered how data structures in Java expand dynamically? Here's a quick look at how some prominent data structures handle growth: ⮕ ArrayList: ArrayList is a resizable array implementation of the List interface. It starts with an initial capacity, defaulting to 10. When the number of elements exceeds the current capacity, it increases by 50%, making the new capacity 1.5 times the original. ⮕ HashMap and HashSet: These hash-based collections grow dynamically based on their load factor and capacity. They start with an initial capacity of 16 and a load factor of 0.75, When the size exceeds capacity * loadFactor, they resize (usually doubling) and rehash all entries to new buckets. Read more about this at - https://lnkd.in/dM-aqnR6 ⮕ LinkedList: LinkedList, a doubly-linked list implementation of the List and Deque interfaces, doesn't have an initial capacity or need to resize since each node is linked to the next as elements are added. Follow me Yash Gupta #optimization #evolution #arraylist #java #latency #hash #map #follow #treemap #events #javamagic #support #interview
To view or add a comment, sign in
-
Let's talk about "knowing CS basics". A stroll through time: * 50s-ish, GOTOs, COBOL, Fortran, Assembly for memory management. * 60s-ish: Subroutines (procedural), the origins of today's relational DBs. + Interwebz honorary plug: ARPANET '69. * 70s: Bell Labs slaps. C comes out, UNIX development slowly starts. + Interwebz honorary plug: Bob n Vint start on TCP/IP protocols * 80s: Bell Labs keeps slappin'. C++ comes out, the world is rizzed. + Interwebz honorary plug: NSFNET. internet but now for civvies. ...Remember when your mouse was RS-232 and the ball in it could readily be used in a 8-12 gauge shotgun as effective ammo against a grizzly? * 90s: the World Wide Web as we know it, Browser GUIs, Email, Search Engine, E-commerce, modern mobile phones, SMS, WiFi, MP3, Bluetooth, HTML/JS, 3D graphics and gaming ...and, unfortunately, Java. * 00s: started off with Y2K horror, followed promptly by the horrors of social media, smartphones, streaming, "Web 2.0", cloud / virtualization, USB, 3G. ...and Java - the menace to rule them all. Point is: Assembly was "essential" until it got abstracted by malloc / pointers / semaphores / mutexes / etc. Then memory management and parallelism got abstracted by threads n classes. Now we have stuff like Python and JS. The "absolutely necessary basics" at any given time are layers of abstraction that were at the top 2-3 layers ago. Today's flavor of the month is "Data Structures and Algorithms 101 for your next FAANG interview". The last few layers are preached as "critical" because that's as deep as you have to go to be able to handle 99.9%+ of times things go wrong or if you are working at scale (read: 10+Gbps net ingress / 100Gbps+ net egress) Most relevant example: SQL used to be "must-know" for everything and now ORMs are fine for most use cases unless you're plowing through GBps or TBps (aka you work at big 5) of streams or data. Where does that leave us with the latest layer of abstraction, LLMs, and what layers does it push out of "necessary basics"? You need to know enough to sh*t check the output pre-copy/pasta and fix it if the top layer is wrong. The only thing different this time is the operating cost and performance degradation gaps between misapplying ML and using good ole statistics are much larger than we've seen in recent times. Especially for operational costs at scale. Think math before abacuses, or books before the printing presses. You know how your Databricks or Snowflake bills start becoming 5%, then 10%, then eventually 20%+ of your total revenue in operating cost when you have an inferior data team for long enough? Yeah, it's exactly like that. Now think about the latest "cutting edge" AI use case your org deployed amongst roaring glee and applause from its' shareholders and execs ...and how good or bad (spoiler: mostly bad) RAG is at 10Gb+ vector DB size, whether you should've just used Algolia or ElasticSearch, and how expensive it will be YoY.
To view or add a comment, sign in
-
6 months progress condensed into a picture,hit the 150 mark today ★ Topics covered so far- 1) Hashtable 2) Arrays/string 3) Linked List 4) Stacks 5) Queues 6) Sliding window 7) Prefix sum 8) Two pointer Algorithm 9) Binary Search ★ Next target- Non-linear Data structures #Leetcode #DSA #Java
To view or add a comment, sign in
-
Day 11/100 of #100DaysOfLeetCode : Sum of Prefix Scores of Strings Today's challenge dives into the world of prefixes and efficient data structures. We tackled the "Sum of Scores of Prefixes" problem, where we're given an array of strings and need to calculate the sum of scores for each string's prefixes. Approach: The core concept was to use a Trie (Prefix Tree) to store all the words. As we insert words into the Trie, we also keep track of how many words share each prefix. This allows us to efficiently calculate the score for any prefix by simply looking it up in the Trie. 1. Trie Implementation: We built a custom Node class to represent each node in the Trie, storing a count of words passing through that node and links to child nodes. 2. Insertion & Counting: We carefully inserted each word into the Trie, Incrementing the count at each node along the way. 3. Prefix Score Calculation: For each word, we traversed its prefixes in the Trie and summed up the counts to get the final score. #100DaysOfLeetCode #Java #DataStructures #Tries #Prefixes
To view or add a comment, sign in
-
𝐖𝐡𝐲 𝐀𝐫𝐞 𝐉𝐚𝐯𝐚 𝐒𝐭𝐫𝐢𝐧𝐠𝐬 𝐈𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞? While it might seem like we can easily modify strings through manipulation or concatenation, 𝐉𝐚𝐯𝐚 𝐒𝐭𝐫𝐢𝐧𝐠𝐬 𝐚𝐫𝐞 𝐢𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞. This means that once a string is created, it cannot be changed. String x = "adeel"; // A new string is created. x = x + "-dev"; // This creates a new string, pointing x to a different memory reference. When I first learned about this, I was curious why strings work this way. Here are several key reasons: 1️⃣ 𝐒𝐞𝐜𝐮𝐫𝐢𝐭𝐲 Strings are used as parameters or arguments in sensitive contexts like database connection URLs, usernames/passwords, network connections, and class loading. If strings were mutable, these parameters could easily be manipulated, leading to security risks and errors. 2️⃣ 𝐓𝐡𝐫𝐞𝐚𝐝 𝐒𝐚𝐟𝐞𝐭𝐲 In multi-threaded environments, strings are frequently shared between threads. Since strings are immutable, they can be shared safely without synchronization. Means one thread cannot modify the content of string while other is reading it, preventing race conditions. 3️⃣ 𝐇𝐚𝐬𝐡𝐢𝐧𝐠 Strings are widely used in hash-based collections like 𝘏𝘢𝘴𝘩𝘔𝘢𝘱, 𝘏𝘢𝘴𝘩𝘚𝘦𝘵, etc. Immutability ensures that hashcode of string is computed only once and remain constant throughout its lifetime. If strings were mutable, any modification would require recalculating the hashcode, which might lead to data loss issues such as losing string's value in map. 4️⃣ 𝐒𝐭𝐫𝐢𝐧𝐠 𝐏𝐨𝐨𝐥𝐢𝐧𝐠 Unlike other objects, string literals are stored in a special memory region called the 𝐒𝐭𝐫𝐢𝐧𝐠 𝐏𝐨𝐨𝐥 (a part of the heap). The JVM optimizes memory usage by storing only one copy of each string literal in the pool. When you create a string using a literal, it checks the pool to see if that string already exists, and if so, it reuses the existing reference. String x = "abc"; String y = "abc"; // does not create a new string in the pool. Both 𝐱 and 𝐲 refer to the same string in the pool, conserving memory. Although strings are immutable through its public API, they can still be modified using 𝐉𝐚𝐯𝐚 𝐑𝐞𝐟𝐥𝐞𝐜𝐭𝐢𝐨𝐧. #Java #Spring #SoftwareEngineering #CodingTips
To view or add a comment, sign in
-
Array is a fixed size index based data structure containing similar type of objects. For example : int[] a = new int[10] -> It is an array of 10 integers. char[] c = new char[15] -> It is an array of 15 characters. String[] s = new String[20] -> It is an array of 20 strings. Array Structure : Arrays in Java use zero-based indexing to store the elements where first element is stored at 0th index, second element at 1st index, third element at 2nd index and so on. Array Declaration : There are two ways to declare arrays in Java. int[] intArray; OR int intArray[]; Array Initialization : There are three ways to initialize array elements. Initializing individual elements int[] intArray = new int[5]; intArray[0] = 21; intArray[1] = 15; intArray[2] = 37; intArray[3] = 53; intArray[4] = 17;
To view or add a comment, sign in
SDE - 1 Fullstack @StackWealth (YC S21) | ICPC Regionalist | 3x YC dev
5dTools used: Stack + Heap Trace(Rust): https://cel.cs.brown.edu/aquascope/ Stack + Heap Trace(Java): https://pythontutor.com/render.html