Skip to content

alloca() #2

Description

@bestouff

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

Activity

  1. petertodd commented on Aug 30, 2017

    @petertodd
    Owner

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

  2. bestouff commented on Aug 30, 2017

    @bestouff
    ContributorAuthor

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

  3. petertodd commented on Aug 30, 2017

    @petertodd
    Owner

    Thanks! I'll take a look.

  4. petertodd commented on Aug 31, 2017

    @petertodd
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions