-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
correctly track freed bytes in array_to_string #54309
Conversation
I'm a bit confused, because the array you get is empty julia> a = rand(UInt8, 5)
5-element Vector{UInt8}:
0xda
0x73
0x44
0x3e
0xb5
julia> str = String(a)
"\xdasD>\xb5"
julia> a
UInt8[] So i'm a bit suspicious of how this is implemented. This is |
Yes, that's one source of confusion for me as well. As it is, it seems like For some reason, we're still resetting the indices of the I see two paths forward:
|
Three possible paths forward, actually, the third one being what you suggested: implement a function to free the buffer which has been moved and make sure it's correctly accounted in GC live bytes. |
I believe the issue is that ->maxsize shouldn't be reset. The others should be reset. |
Yes, this does solve #54275. Still, it's a bit odd that constructing a If this is breaking, then yes, let's just solve the accounting bug and keep the observable behavior of |
I think the current behavior of taking ownership is desired for performance. If you have a 1gb Vector{Uint8} having to copy all that data to get a string will be pretty slow (and double your memory requirement). |
If I'm not misunderstanding something, that's precisely what we do in the C Array implementation? Link. |
Right, so if you don't copy the memory, the reason we set maxsize to 0 is to prevent the original array from mutating the string afterward. |
I meant to say that at least in |
In that context, I really have no idea why we're doing this (but I want to make sure @vtjnash gets a chance to weigh in here) |
This case is only if you built the array weirdly for constructing a string (eg with pushfirst). If we have to copy the data anyways to shift it, we might as well allocate a new one of the exact right size too |
960e5bc
to
8923c66
Compare
In that case, to avoid changing the behavior of resetting the array, I just added a call ( Does it seem more reasonable to you folks? |
I think your previous change (only maxsize) is more correct here. Because the buffer hasn't been freed yet, we've just resized the array, the memory is still there. |
960e5bc
to
7b08f4c
Compare
@gbaraldi that fix isn't correct because with it, a |
That is not quite accurate. It is not moving memory, as that memory was always owned by the String, it is simply deleting the reference to that String that used to be part of the Array. |
So we are talking about the case at the bottom where we just make a copy. |
Bump. |
Can you also make the master version of this PR? |
…54331) Master version of JuliaLang#54309. Should fix JuliaLang#54275. --------- Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Should fix #54275.