mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-24 15:25:20 +00:00
Add ptr_to_bytes
This commit is contained in:
@@ -41,6 +41,16 @@ slice_to_bytes :: proc "contextless" (slice: $E/[]$T) -> []u8 {
|
||||
return transmute([]u8)s;
|
||||
}
|
||||
|
||||
ptr_to_bytes :: proc "contextless" (ptr: ^$T, len := 1) -> []u8 {
|
||||
assert(len >= 0);
|
||||
return transmute([]u8)raw.Slice{ptr, len*size_of(T), len*size_of(T)};
|
||||
}
|
||||
|
||||
ptr_to_bytes :: proc "contextless" (ptr: ^$T, len, cap: int) -> []u8 {
|
||||
assert(0 <= len && len <= cap);
|
||||
return transmute([]u8)raw.Slice{ptr, len*size_of(T), cap*size_of(T)};
|
||||
}
|
||||
|
||||
|
||||
kilobytes :: inline proc "contextless" (x: int) -> int do return (x) * 1024;
|
||||
megabytes :: inline proc "contextless" (x: int) -> int do return kilobytes(x) * 1024;
|
||||
|
||||
Reference in New Issue
Block a user