-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
XXX [mycpp] add LinkedList #1769
Conversation
This commit adds LinkedList, which implements a simple doubly-linked list. This will be useful for building caches.
Hmm is there any reason to make it GC-managed? I think the ownership is clear for a cache -- it's global and can be torn down at process exit i.e. We could just have our own simple manually managed linked list. Oh OK well I guess a reason is if the entries themselves are GC objects. In this case the value is a But we could also have the cache own copies of the Str as a Tracing is still expensive on some workloads http://travis-ci.oilshell.org/github-jobs/5644/raw-vm.wwz/_tmp/perf/osh-parse.report.txt I would tend to go for the minimal thing that will solve regcomp() first ... i.e. whatever makes it fast Not sure if it has to be integrated with the GC |
Oh yeah and remember we actually have no code hooks for deallocating ... So we have to figure out where to put the I guess that's a main goal -- to prevent that potentially infinite memory leak (while not redoing regcomp() and regfree() every time unnecessarily) The dealloc hook / finalizer is a pretty hard problem and I don't think we need it in general, since this is I think the first time its come up |
} | ||
|
||
static constexpr uint32_t field_mask() { | ||
return maskbit(offsetof(LinkedListNode, obj_)) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is tricky because whether this bit is set depends on whether T is a pointer or not
In the unit tests, it looks like it's not a pointer, which I think means bad things will happen here
For Slab and Tuple{2,3,4} I think we're using std::is_pointer<T>
at compile time to conditionally set the mask! That took a bit of figuring out ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch
Oh, yeah. I guess this doesn't need to be managed by the GC (marking all the nodes could be wasteful...). I went with this since we needed
This probably isn't necessary. The cache type that uses this list will still have to have a
Oh, yeah, this could be messy. The clearest spot to add this is probably at evict-time. Two ideas below. We could have Maybe we could have the user provide a cleanup method in the constructor? We could have |
Hm yeah not sure, I'd be tempted just to hard-code regfree() and see what it looks like It doesn't have to be generic at first I think the other instances of LRU caches are in Python code, and it seems like we're not sure how or if to unify them ... In general I think this is tricky / unique because it's one of few places (only place?) where we actually have a heap object of a type we didn't define ourselves -- the |
Hmm ok. Let me ditch this pr and just send some specialized thing then |
This commit adds LinkedList, which implements a simple doubly-linked list. This will be useful for building caches.