-
Notifications
You must be signed in to change notification settings - Fork 6
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
use counted pointer to hold values #326
Open
jingkaimori
wants to merge
11
commits into
main
Choose a base branch
from
jingkaimori/counted-ptr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Charonxin
reviewed
May 21, 2024
} | ||
} | ||
else { | ||
counter->inc_count (); |
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.
Why this statement in two branchs looks like same?
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.
the only difference is null checking
c8f7dc6
to
bd8a506
Compare
Charonxin
approved these changes
May 22, 2024
because pointer does not need to know which type is hold at body.
fix compile error on blackbox
b28aadf
to
71a7e17
Compare
71a7e17
to
e79e91f
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This pr replaces
ABSTRUCT_XXX
andCONCRETE_XXX
with unified reference counted pointer, as a replacement of #263. Similar works can be found at https://github.com/mgubi/texmacs/tree/restructureConcrete struct (defined by
CONCRETE
,*_rep
and so on) is used as reference counter. For example, type T is implemented as two class: T_rep handles properties of given type, and T handles reference and counter of references to T_rep. When T is assigned, only reference is assigned with counter in/decreased.Works
tm_new<xxx>
string_u16
withcounted_ptr
blackbox
withcounted_ptr
tm_ostream
withcounted_ptr
Question
Can managed pointer point to a literal type?
Currently there is no way to get address of literal object, especially when the object is created from inside of other function, such as constructor of managed pointer. See 为什么很多std容器不能作为编译期常量? - 暮无井见铃的回答 - 知乎 for more information.
Why managed pointer holds two pointers, even though pointer of instance can be retrieved from pointer of reference counter?
Performance. Multilevel pointer and member is less effective than single cached pointer.
Are there differences between template and non-template subclass of managed pointer?
Sadly yes, there are some significant difference:
base
alias type must be exploited manually to subclass ofcounted_ptr
;make
method.Performance
Construction is faster, but access is a bit slower:
Before
construct string_u16
construct string_u16 with content
equality of string
equality of larger string
compare string
compare larger string
slice string
slice string with larger range
(Unstable with ~1,595,528.7 iters. IncreaseminEpochIterations
to e.g. 15955287)concat string
append string
(Unstable with ~217,087.1 iters. IncreaseminEpochIterations
to e.g. 2170871)After
construct string_u16
construct string_u16 with content
equality of string
equality of larger string
compare string
compare larger string
slice string
slice string with larger range
(Unstable with ~3,444,501.7 iters. IncreaseminEpochIterations
to e.g. 34445017)concat string
append string
(Unstable with ~217,087.1 iters. IncreaseminEpochIterations
to e.g. 2170871)