Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Comparing linked lists with pre-allocated array #710

Open
CuriousLocky opened this issue Nov 7, 2022 · 0 comments
Open

[Question] Comparing linked lists with pre-allocated array #710

CuriousLocky opened this issue Nov 7, 2022 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@CuriousLocky
Copy link

CuriousLocky commented Nov 7, 2022

In today's lecture, we talked about the reason Linux uses linked lists for managing threads, instead of using arrays (with bitmaps indicating each element's state).
The main reason seems to be that when using arrays, and the number of elements that need to be stored exceeds the size of the array, a new allocation is needed, which is undesired.

But I'd like to ask why we don't use a pre-allocated array, which is large enough to hold any possible number of elements.
My question is based on the following assumptions:

  • The maximum number of elements is usually bounded
    • For example, bounded by physical memory size, or the system configuration (in the case of number of threads)
  • Most OSes (including Linux) allocate physical memory lazily
    • Thus, having a large uninitialized array would not create memory utilization problem
  • 64-bit virtual memory space is big
@CuriousLocky CuriousLocky added the question Further information is requested label Nov 7, 2022
@Lee-Janggun Lee-Janggun added the lecture question/discussion related to lectures label Nov 7, 2022
@Lee-Janggun Lee-Janggun removed the lecture question/discussion related to lectures label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants