Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Froot75547yI don't follow, what's an actual array then?
Edit: Nvm a quick Google search solved it π -
I think many languages cheat a bit with their data structure naming, because for 99% of devs it really doesn't matter how data is stored in memory, as long as it works.
Just like how sorting algorithms are cute to learn about in college, but in practice you just call data.sort() and the language picks some quicksort.
Although just like with cars, going manual sometimes gives you a bit of extra performance... -
meister3437yTrue. Came from backend dev.
Currently doing js for front end dynamicability. Poof. Many things are different -
CWins48117y@No-one
Okay, so you're not meaning lists as in "linked lists" or these other list-named structures in classic computer science. -
vadimir2007y@No-one
i know that lists have a different allocation algorithms than vectors. and i mentioned vectors because its what you meant (is it called meant?) by saying that said data structures acts similarly to an array.
in terms usefullness vectors always surpass lists in terms of access speed and stability as long as you you dont have to reallocate shit or have the time to do such operations in the background.
and now to @CWins screenshot
it looks to me like an array inside the heap which makes the structure technically a vector.
in the other hand its js and all i know is that its fucking nuts to try to understand how a program written in a scripting language ist structured in terms of memory usage unless you are a developer of said language -
CWins48117yMy screenshot is c# @vadimir.
I like c++ vectors. No surprise the c# defaultlist is like that. It's a good combination of simple in technical terms and usability. -
vadimir2007y@No-one
i would like to test that but im pretty they dont use more memory. ofc if you want to use them properly you have to use more memory because you want to avoid reallocation in an unpredictable state.
in terms of access speed it depends highly in the low level possibilities of the cpu. if you are able to jump from one item of a list to the next with the same amount of cycles you need to increase an adress already loaded inside the register. then you are right. on such a cpu lists have no disadvantages in terms of access speed compared to arrays -
CWins48117y@No-one
That's why i mentioned the .net list as an array (though thats not the most precise description). Simple Add/Delete methods are a common thing these days and without knowing the internals, it's easy to waste performance by not setting the capacity before adding 10000 values. -
meowth4297yTo be fair from a classical definition perspective. The array in JS works like an arraylist. if you analyze it's performance characteristics you get O(1) index look ups. O(1) additions. Slicing and all those operations are easy with lists, but harder with arrays. Also, standard arrays suffer from resizing every now and then. Can you imagine if almost every page had a "stop the world" gotta resize this fucking array issue.
-
vadimir2007y@meowth
standard arrays dont suffer from resizing because they are static. dont confuse standard arrays with dynamic arrays aka vectors -
meowth4297y@vadimir sorry, I meant, the array implementation that most people end up using. I've very rarely used an array that didn't change in size... Maybe if delivered from a server side payload or something.
-
elazar10307y@No-one for *most* uses, vectors (dynamic arrays) are much more efficient than linked lists. The reason is memory locality.
-
elazar10307yThe discussion somewhat confuses implementation, interface and performance characteristics.
The two major implementations for a growable sequence are linked list and dynamic array.
Linked lists do not require contiguous memory, and can guarantee O(1) worst case for appending and prepending an element. Accessing an item in the middle is O(n) non-local memory accesses, which is bad. Also O(n) memory overhead.
Dynamic arrays (C++ vector, Python lists) have O(1) memory overhead; O(1) access, usually 1-3 machine instructions; appending an element is O(1) amortized, which is good unless you have hard real time requirements; and prepending an element is O(n). Operations are very local in memory so they are very fast on modern hardware. -
meowth4297y@elazar if you are looking at the characteristics of a data structure without needing to know it's implementation the only characteristics that matter are its apis and performance. It is why you can safely use objects as hash maps in JS. The performance characteristics and APIs are such that they resemble hashmaps and that's all that matters. It is also why arrays in JS can be treated as stacks, queues, arrays and linked lists.
I guess I'm saying the performance characteristics describe the data structure equivalently to the API it provides. -
@bittersweet I often end up implementing linked list like data structures myself, because they are really handy for some applications (especially for chaining stuff like data processing chains, eg. neural network layers).
Related Rants
When you realize JS Arrays are actually lists instead of actual arrays
undefined
js
lists
arrays