-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add WeakRef class #3276
Add WeakRef class #3276
Conversation
2f128b0
to
7a0c700
Compare
@@ -0,0 +1,70 @@ | |||
require "spec" | |||
|
|||
class State |
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.
State
and Foo
might eventually conflict with other specs. Maybe use names like WeakRefState
and WeakRefFoo
?
This is one of the reasons I want to implement file-private types.
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.
I would prefer a spec-specific solution, of somehow being able to define helper classes and functions in the namespace of a describe Foo
statement. This seems possible with macros, and I much prefer it as a solution than having file-private classes and methods.
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.
file-private classes are a general solution, I don't understand why we should go with a less general solution. I also want to use it here, and this is not a spec. Sometimes there are some classes that only makes sense in a file, just like some functions that only make sense in a single file.
7a0c700
to
5436fd6
Compare
end | ||
|
||
def self.allocate | ||
GC.malloc_atomic(sizeof(WeakRef(T))).as(WeakRef(T)) |
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.
Does using self
instead of WeakRef(T)
work? (shorter and maybe more clear)
5436fd6
to
03a2dd3
Compare
I didn't update gc/null.cr to match gc/boehm.cr. Should I? They already differ on |
I don't think |
It could be a pro to keep gc/null up to date - to maintain perspective, not unnecessarily naming/implementing funcs that are too tied to Boehm specifically (in this case, primarily the name), if a more general interface could easily be defined. For the future. |
Weak references are implemented by boehm's register_disappearing_link
03a2dd3
to
efead56
Compare
@ozra , any gc-agnostic terms you would suggest? Let's handle gc/null or rewording of the methods in a separate issue, if needed. |
Yes, I guess when the time comes, a few refactors in stdlib code won't be too much handle (not much user code should rely on GC-funcs anyway), so ignore my bike-shedding :-) I started on a PoC-GC-experiment for Crystal a few months ago, but it's far down on my urgent list, otherwise I wouldn't even have blinked ;-) Until the parallelism model is settled, there's not much point making a hot rod anyway. |
Weak references are implemented by boehm's register_disappearing_link