This commit is contained in:
gingerBill
2021-08-07 15:07:29 +01:00
parent 16eeae36d7
commit 423b842347
2 changed files with 12 additions and 12 deletions
+6 -6
View File
@@ -173,7 +173,7 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
} break; } break;
case gbAllocation_Resize: case gbAllocation_Resize:
if (new_size == 0) { if (size == 0) {
free(old_memory); free(old_memory);
break; break;
} }
@@ -182,14 +182,14 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
gb_zero_size(ptr, size); gb_zero_size(ptr, size);
break; break;
} }
if (new_size <= old_size) { if (size <= old_size) {
ptr = old_memory; ptr = old_memory;
break; break;
} }
ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1)); ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1));
gb_memmove(ptr, old_memory, old_size); gb_memmove(ptr, old_memory, old_size);
gb_zero_size(cast(u8 *)ptr + old_size, gb_max(new_size-old_size, 0)); gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0));
break; break;
#else #else
// TODO(bill): *nix version that's decent // TODO(bill): *nix version that's decent
@@ -203,7 +203,7 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
break; break;
case gbAllocation_Resize: case gbAllocation_Resize:
if (new_size == 0) { if (size == 0) {
free(old_memory); free(old_memory);
break; break;
} }
@@ -212,14 +212,14 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
gb_zero_size(ptr, size); gb_zero_size(ptr, size);
break; break;
} }
if (new_size <= old_size) { if (size <= old_size) {
ptr = old_memory; ptr = old_memory;
break; break;
} }
posix_memalign(&ptr, alignment, size); posix_memalign(&ptr, alignment, size);
gb_memmove(ptr, old_memory, old_size); gb_memmove(ptr, old_memory, old_size);
gb_zero_size(cast(u8 *)ptr + old_size, gb_max(new_size-old_size, 0)); gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0));
break; break;
#endif #endif
+6 -6
View File
@@ -5037,7 +5037,7 @@ GB_ALLOCATOR_PROC(gb_heap_allocator_proc) {
} break; } break;
case gbAllocation_Resize: case gbAllocation_Resize:
if (new_size == 0) { if (size == 0) {
free(old_memory); free(old_memory);
break; break;
} }
@@ -5046,14 +5046,14 @@ GB_ALLOCATOR_PROC(gb_heap_allocator_proc) {
gb_zero_size(ptr, size); gb_zero_size(ptr, size);
break; break;
} }
if (new_size <= old_size) { if (size <= old_size) {
ptr = old_memory; ptr = old_memory;
break; break;
} }
ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1)); ptr = aligned_alloc(alignment, (size + alignment - 1) & ~(alignment - 1));
gb_memmove(ptr, old_memory, old_size); gb_memmove(ptr, old_memory, old_size);
gb_zero_size(cast(u8 *)ptr + old_size, gb_max(new_size-old_size, 0)); gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0));
break; break;
#else #else
// TODO(bill): *nix version that's decent // TODO(bill): *nix version that's decent
@@ -5067,7 +5067,7 @@ GB_ALLOCATOR_PROC(gb_heap_allocator_proc) {
} break; } break;
case gbAllocation_Resize: { case gbAllocation_Resize: {
if (new_size == 0) { if (size == 0) {
free(old_memory); free(old_memory);
break; break;
} }
@@ -5076,14 +5076,14 @@ GB_ALLOCATOR_PROC(gb_heap_allocator_proc) {
gb_zero_size(ptr, size); gb_zero_size(ptr, size);
break; break;
} }
if (new_size <= old_size) { if (size <= old_size) {
ptr = old_memory; ptr = old_memory;
break; break;
} }
posix_memalign(&ptr, alignment, size); posix_memalign(&ptr, alignment, size);
gb_memmove(ptr, old_memory, old_size); gb_memmove(ptr, old_memory, old_size);
gb_zero_size(cast(u8 *)ptr + old_size, gb_max(new_size-old_size, 0)); gb_zero_size(cast(u8 *)ptr + old_size, gb_max(size-old_size, 0));
} break; } break;
#endif #endif