Skip to content

It's not possible to open a file without invoking allocations for the file name #22190

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

Closed
tbu- opened this issue Feb 11, 2015 · 9 comments · Fixed by #24452
Closed

It's not possible to open a file without invoking allocations for the file name #22190

tbu- opened this issue Feb 11, 2015 · 9 comments · Fixed by #24452

Comments

@tbu-
Copy link
Contributor

tbu- commented Feb 11, 2015

File::open takes a Path object as reference, although it only clones it afterwards.

It's also impossible to re-use the allocation for the file path, because it's only dropped at the end.

@nagisa
Copy link
Member

nagisa commented Feb 11, 2015

It is pretty hard to not involve allocations because Rust-native strings will have to be converted into null terminated one to pass into the native API at some point anyway.

@tbu-
Copy link
Contributor Author

tbu- commented Feb 11, 2015

That's true.. Maybe we can avoid the double-allocation?

@aturon
Copy link
Member

aturon commented Feb 16, 2015

@tbu- The path is cloned only so that it can later be used in error messages, which is a somewhat debatable use case.

We could resolve this in the future by taking an IntoPathBuf bound (if we had a trait like that).

cc @wycats @alexcrichton

@tbu-
Copy link
Contributor Author

tbu- commented Feb 16, 2015

@aturon In that case it would probably be better to just take a PathBuf. But does it really justify an extra allocation just to provide error messages?

@aturon
Copy link
Member

aturon commented Feb 16, 2015

@tbu-

In that case it would probably be better to just take a PathBuf.

That would be a lot less ergonomic -- I want to be able to feed in a string literal with no extra steps.

But does it really justify an extra allocation just to provide error messages?

Probably not, hence why I said it was a "somewhat debatable use case." :)

@alexchandel
Copy link

@nagisa What about a variable-length stack allocation?

@nagisa
Copy link
Member

nagisa commented Feb 21, 2015

@alexchandel allocating on stack comes with its own downsides. Also, it doesn’t guarantee a trailing null byte either, AFAIK?

@tbu-
Copy link
Contributor Author

tbu- commented Feb 21, 2015

@nagisa If you had a stack allocation, you could just append a null byte.

@alexchandel
Copy link

@nagisa As tbu- said. And the downsides of alloca are nothing compared to linking in 195kB of jemalloc (the absolute minimum jemalloc size on OS X x86_64 with LTO).

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

Successfully merging a pull request may close this issue.

5 participants