Skip to content

[proposal] Add an origin parameter to Buffer #15

@martinvuyk

Description

@martinvuyk

Add an origin parameter to Buffer

Maybe we can do this:

struct Buffer[
    mut: Bool, //, *,
    origin: Origin[mut],
    ... # alignment etc.
](Movable):
    alias _U = UnsafePointer[UInt8, mut=mut, origin=origin] # alignment etc.
    # these two fields could also be replaced by `Span[UInt8, origin]`
    var ptr: Self._U
    var size: Int
    var owns: Bool

    fn __init__(out self, ptr: Self._U, size: Int, owns: Bool = True):
        self.ptr = ptr
        self.size = size
        self.owns = owns

    fn alloc[I: Intable, //, T: DType = DType.uint8](length: I) -> Buffer[origin=MutableAnyOrigin.empty]: ...

origins are kept throughout the code this way which is much safer. It will involve a lot of work though.

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