File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -583,6 +583,28 @@ impl<R: Relocation> Assembler<R> {
583583 } )
584584 }
585585
586+ /// Create a new, empty assembler, with a pre-allocated buffer of the specified capacity in bytes,
587+ /// and an initial allocation of `capacity.next_multiple_of(page_size)`.
588+ pub fn new_with_capacity ( capacity : usize ) -> io:: Result < Self > {
589+ // Avoid panic or wraps on overflow.
590+ let memory_size =
591+ capacity
592+ . checked_next_multiple_of ( R :: page_size ( ) )
593+ . ok_or ( io:: Error :: new (
594+ io:: ErrorKind :: InvalidInput ,
595+ "Capacity is too large" ,
596+ ) ) ?;
597+
598+ Ok ( Self {
599+ ops : Vec :: with_capacity ( capacity) ,
600+ memory : MemoryManager :: new ( memory_size) ?,
601+ labels : LabelRegistry :: new ( ) ,
602+ relocs : RelocRegistry :: new ( ) ,
603+ managed : ManagedRelocs :: new ( ) ,
604+ error : None ,
605+ } )
606+ }
607+
586608 /// Create a new dynamic label ID
587609 pub fn new_dynamic_label ( & mut self ) -> DynamicLabel {
588610 self . labels . new_dynamic_label ( )
You can’t perform that action at this time.
0 commit comments