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

alloca() #2

Open
bestouff opened this issue Aug 30, 2017 · 4 comments
Open

alloca() #2

bestouff opened this issue Aug 30, 2017 · 4 comments

Comments

@bestouff
Copy link
Contributor

Would it be possible to use alloca() when available ? This would make allocations equivalent to just a pointer adjust.

@petertodd
Copy link
Owner

Sure. Are you aware of any ways to get alloca() working on Rust?

@bestouff
Copy link
Contributor Author

Not really. Did you read rust-lang/rfcs#618 ? There's a link to an RFC at the bottom: rust-lang/rfcs#1808

@petertodd
Copy link
Owner

Thanks! I'll take a look.

@petertodd
Copy link
Owner

Given that the obstacks implementation already minimizes allocations - particularly if you set an appropriately large initial capacity - I have to wonder how much of a performance benefit this would actually be?

I mean, if you have a working alloca(), it might be better to just use it directly. Also, unlike alloca(), an obstack can be passed to child functions that can in turn add things to the stack, and return references to values within it; I don't see how you could preserve that capability.

That said, what I could do is make the initial allocation on the stack, then switch to the heap when that allocation runs out. That'd probably give you very similar benefits to alloca() for many usecases while still preserving the ability to pass the stack to child functions. Specifically, I could do this by adding another constructor, Obstack::from_initial_slice(initial_slice: &mut [u8]), that the callee could then allocate themselves:

let mut stack_segment: [u8; 1024] = unsafe { std::mem::unitialized() };
let stack = Obstack::from_initial_slice(&stack_segment);

(or via something like ArrayVec to avoid unsafeness)

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