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

Crazy idea: static char arrays instead of global frame_names #79

Closed
rdeits opened this issue Oct 14, 2016 · 4 comments
Closed

Crazy idea: static char arrays instead of global frame_names #79

rdeits opened this issue Oct 14, 2016 · 4 comments

Comments

@rdeits
Copy link
Collaborator

rdeits commented Oct 14, 2016

The global frame_names map has a somewhat scary problem in that every new coordinate frame causes that list to grow, and old entries can never be deleted. So far this hasn't actually cause any measurable issues for me, but it's still concerning.

What if, instead, we used a fixed-size static array of Chars instead of the Int64 reference? That might look something like:

immutable CartesianFrame3D
    name::SVector{64, Char}
    function CartesianFrame3D(name::String)
        length(name) > 64 && warn("Frame name longer than 64 characters was truncated")
        new(SVector{64, Char}(Base.flatten((name[1:min(length(name), 64)], ('\x0' for i in 1:(64 - length(name)))))...))
    end
end

show(io::IO, frame::CartesianFrame3D) = print(io, "CartesianFrame3D: $(join(frame.name[frame.name .!= '\x0'], ""))")

This has the obvious problem that it makes the stack-allocated size of a frame much, much larger. That alone might be enough to make this a very bad idea. However, it does result in an isbits type that doesn't require a global reference.

@tkoolen
Copy link
Collaborator

tkoolen commented Oct 16, 2016

I see this as a place where the language is currently a little bit lacking. My plan was to stick with the current hack until Julia improves. Related Julia issues/PRs:

If this becomes a real problem for you or anybody else, I can try what you proposed. I guess for now, try not to create new frames at every time step of your control algorithm or simulation, or if you must, manually remove the frame_names entries for frames that will go out of scope. Unfortunately I can't use finalizer either since "the behavior of this function is unpredictable if x is of a bits type".

@rdeits
Copy link
Collaborator Author

rdeits commented Oct 16, 2016

Ok, makes sense. I'll let you know if the hack ever causes real problems.

@rdeits rdeits closed this as completed Oct 16, 2016
@tkoolen tkoolen reopened this Oct 27, 2016
@tkoolen
Copy link
Collaborator

tkoolen commented Oct 29, 2016

Another option is to make it possible to have anonymous frames for transient use (e.g. have id == -1 mean anonymous frame, and have name return "(anonymous frame)" in this case).

@tkoolen
Copy link
Collaborator

tkoolen commented Jun 29, 2017

You know what, I'm pretty happy with the current solution; no issues related to this after months, so I'll close this.

@tkoolen tkoolen closed this as completed Jun 29, 2017
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

2 participants