Y
Hacker News
new
|
ask
|
show
|
jobs
by
blibble
3348 days ago
if it's unordered (like you'd expect a list of sockets to be) you can get O(1) removal for an array by swapping the end item into the removed slot
1 comments
dozzie
3348 days ago
...unless something else holds a pointer to the handle you're swapping with.
link
staticassertion
3348 days ago
This is already a problem if you're removing an item, regardless of whether it's done with swap remove or not.
link
toast0
3348 days ago
For the item you're removing, you are presumably removing it because all handles have been closed. But the item you're potentially swapping with may certainly have open handles.
link
staticassertion
3348 days ago
True.
link
blibble
3348 days ago
kernels don't tend to give userspace raw pointers into kernel memory
link
dozzie
3348 days ago
But kernels tend to give raw pointers to other kernel code.
link
blibble
3348 days ago
a good chunk of the fun in kernel code is maintaining the various layers of self-referential lists and dealing with the cleanup
link