diff --git a/mem/mem.go b/mem/mem.go index 94c29fa..b6c9e5a 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -5,7 +5,7 @@ import ( ) const ( - Kilobyte uintptr = 1 << (10 * (iota + 1)) + Kilobyte = 1 << (10 * (iota + 1)) Megabyte Gigabyte Terabyte @@ -110,3 +110,12 @@ func Aligned(address uintptr, alignment uintptr) bool { } return address&(alignment-1) == 0 } + +// ExtendSlice returns a copy of the given slice, increasing its length, but leaving the capacity intact. +func ExtendSlice[T any](slice []T, amount uintptr) []T { + if amount+uintptr(len(slice)) > uintptr(cap(slice)) { + panic("extendslice: cannot extend slice past its capacity") + } + + return slice[: uintptr(len(slice))+amount : cap(slice)] +}