Skip to content
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

Disallow size zero memory #53903

Closed
LilithHafner opened this issue Mar 30, 2024 · 6 comments
Closed

Disallow size zero memory #53903

LilithHafner opened this issue Mar 30, 2024 · 6 comments

Comments

@LilithHafner
Copy link
Member

possibly too late, but would the design have been simpler if we just disallowed 0 length memory? since it's not resizable, there isn't much need to be able to make one.

Originally posted by @oscardssmith in #53896 (comment)

@vtjnash
Copy link
Member

vtjnash commented Mar 30, 2024

Not currently, as it is depended on in quite a few places

@oscardssmith
Copy link
Member

which places? The only ones I can think of at the moment are they are constructed by empty arrays and Dicts. Changing those to allocate ones with a minimal capacity would allow us to remove the boundscheck in memoryrefget/set and the caching of size 0 memories. Is there additional problems we would incur that I'm missing?

@oscardssmith
Copy link
Member

ah, is the problem that we use jl_an_empty_memory_any as a "null" value in a lot of typemap.c?

@jakobnissen
Copy link
Contributor

From a user POV, I like being able to have zero-sized memory. Not allowing it would be an strange inconsistency (similar to say, not allowing zero-sized strings), and it also happens to make a useful placeholder value which can be more practical than a Nothing.

@mikmoore
Copy link
Contributor

mikmoore commented Apr 1, 2024

It would be nifty if creating size zero memory didn't actually result in an allocation (e.g., all size zero memory aliased to the same address). For example, if calls of pointer(Float64[]) happened to always point to some static and unreadable address until the vector is resized. But maybe there are good reasons not to do this (it sounds like a null pointer and I hear those aren't very popular these days).

EDIT: never mind. I didn't check this on 1.11 so didn't see that it's already a thing. Thanks for (ahem) pointing this out.

@oscardssmith
Copy link
Member

@mikmoore good news for you:

julia> @btime Memory{Int}(undef, 0)
  1.716 ns (0 allocations: 0 bytes)
0-element Memory{Int64}

@KristofferC KristofferC removed this from the 1.11 milestone Apr 4, 2024
@LilithHafner LilithHafner closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants