|
@@ -189,7 +189,7 @@ delete :: proc{
|
|
// The new built-in procedure allocates memory. The first argument is a type, not a value, and the value
|
|
// The new built-in procedure allocates memory. The first argument is a type, not a value, and the value
|
|
// return is a pointer to a newly allocated value of that type using the specified allocator, default is context.allocator
|
|
// return is a pointer to a newly allocated value of that type using the specified allocator, default is context.allocator
|
|
@builtin
|
|
@builtin
|
|
-new :: proc($T: typeid, allocator := context.allocator, loc := #caller_location) -> (^T, Allocator_Error) #optional_second {
|
|
|
|
|
|
+new :: proc($T: typeid, allocator := context.allocator, loc := #caller_location) -> (^T, Allocator_Error) #optional_allocator_error {
|
|
return new_aligned(T, align_of(T), allocator, loc)
|
|
return new_aligned(T, align_of(T), allocator, loc)
|
|
}
|
|
}
|
|
new_aligned :: proc($T: typeid, alignment: int, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) {
|
|
new_aligned :: proc($T: typeid, alignment: int, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) {
|
|
@@ -199,7 +199,7 @@ new_aligned :: proc($T: typeid, alignment: int, allocator := context.allocator,
|
|
}
|
|
}
|
|
|
|
|
|
@builtin
|
|
@builtin
|
|
-new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) #optional_second {
|
|
|
|
|
|
+new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) #optional_allocator_error {
|
|
t_data := mem_alloc_bytes(size_of(T), align_of(T), allocator, loc) or_return
|
|
t_data := mem_alloc_bytes(size_of(T), align_of(T), allocator, loc) or_return
|
|
t = (^T)(raw_data(t_data))
|
|
t = (^T)(raw_data(t_data))
|
|
if t != nil {
|
|
if t != nil {
|
|
@@ -210,7 +210,7 @@ new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_locat
|
|
|
|
|
|
DEFAULT_RESERVE_CAPACITY :: 16
|
|
DEFAULT_RESERVE_CAPACITY :: 16
|
|
|
|
|
|
-make_aligned :: proc($T: typeid/[]$E, #any_int len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
|
|
|
|
|
|
+make_aligned :: proc($T: typeid/[]$E, #any_int len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_allocator_error {
|
|
make_slice_error_loc(loc, len)
|
|
make_slice_error_loc(loc, len)
|
|
data, err := mem_alloc_bytes(size_of(E)*len, alignment, allocator, loc)
|
|
data, err := mem_alloc_bytes(size_of(E)*len, alignment, allocator, loc)
|
|
if data == nil && size_of(E) != 0 {
|
|
if data == nil && size_of(E) != 0 {
|
|
@@ -221,19 +221,19 @@ make_aligned :: proc($T: typeid/[]$E, #any_int len: int, alignment: int, allocat
|
|
}
|
|
}
|
|
|
|
|
|
@(builtin)
|
|
@(builtin)
|
|
-make_slice :: proc($T: typeid/[]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
|
|
|
|
|
|
+make_slice :: proc($T: typeid/[]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_allocator_error {
|
|
return make_aligned(T, len, align_of(E), allocator, loc)
|
|
return make_aligned(T, len, align_of(E), allocator, loc)
|
|
}
|
|
}
|
|
@(builtin)
|
|
@(builtin)
|
|
-make_dynamic_array :: proc($T: typeid/[dynamic]$E, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
|
|
|
|
|
|
+make_dynamic_array :: proc($T: typeid/[dynamic]$E, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_allocator_error {
|
|
return make_dynamic_array_len_cap(T, 0, DEFAULT_RESERVE_CAPACITY, allocator, loc)
|
|
return make_dynamic_array_len_cap(T, 0, DEFAULT_RESERVE_CAPACITY, allocator, loc)
|
|
}
|
|
}
|
|
@(builtin)
|
|
@(builtin)
|
|
-make_dynamic_array_len :: proc($T: typeid/[dynamic]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
|
|
|
|
|
|
+make_dynamic_array_len :: proc($T: typeid/[dynamic]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_allocator_error {
|
|
return make_dynamic_array_len_cap(T, len, len, allocator, loc)
|
|
return make_dynamic_array_len_cap(T, len, len, allocator, loc)
|
|
}
|
|
}
|
|
@(builtin)
|
|
@(builtin)
|
|
-make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, #any_int len: int, #any_int cap: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_second {
|
|
|
|
|
|
+make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, #any_int len: int, #any_int cap: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_allocator_error {
|
|
make_dynamic_array_error_loc(loc, len, cap)
|
|
make_dynamic_array_error_loc(loc, len, cap)
|
|
data := mem_alloc_bytes(size_of(E)*cap, align_of(E), allocator, loc) or_return
|
|
data := mem_alloc_bytes(size_of(E)*cap, align_of(E), allocator, loc) or_return
|
|
s := Raw_Dynamic_Array{raw_data(data), len, cap, allocator}
|
|
s := Raw_Dynamic_Array{raw_data(data), len, cap, allocator}
|
|
@@ -253,7 +253,7 @@ make_map :: proc($T: typeid/map[$K]$E, #any_int cap: int = DEFAULT_RESERVE_CAPAC
|
|
return m
|
|
return m
|
|
}
|
|
}
|
|
@(builtin)
|
|
@(builtin)
|
|
-make_multi_pointer :: proc($T: typeid/[^]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (mp: T, err: Allocator_Error) #optional_second {
|
|
|
|
|
|
+make_multi_pointer :: proc($T: typeid/[^]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (mp: T, err: Allocator_Error) #optional_allocator_error {
|
|
make_slice_error_loc(loc, len)
|
|
make_slice_error_loc(loc, len)
|
|
data := mem_alloc_bytes(size_of(E)*len, align_of(E), allocator, loc) or_return
|
|
data := mem_alloc_bytes(size_of(E)*len, align_of(E), allocator, loc) or_return
|
|
if data == nil && size_of(E) != 0 {
|
|
if data == nil && size_of(E) != 0 {
|