emmalloc_aligned_realloc_uninitialized() is like aligned_realloc(), but old memory contents will be undefined after reallocation. (old memory is not preserved in any case)
| 1081 | // emmalloc_aligned_realloc_uninitialized() is like aligned_realloc(), but old memory contents |
| 1082 | // will be undefined after reallocation. (old memory is not preserved in any case) |
| 1083 | void *emmalloc_aligned_realloc_uninitialized(void *ptr, size_t alignment, size_t size) { |
| 1084 | if (!ptr) { |
| 1085 | return emmalloc_memalign(alignment, size); |
| 1086 | } |
| 1087 | |
| 1088 | if (size == 0) { |
| 1089 | free(ptr); |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
| 1093 | if (size > MAX_ALLOC_SIZE) { |
| 1094 | #ifdef EMMALLOC_VERBOSE |
| 1095 | MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + Number($0) + 'bytes! (negative integer wraparound?)'), size); |
| 1096 | #endif |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | size = validate_alloc_size(size); |
| 1101 | |
| 1102 | // Calculate the region start address of the original allocation |
| 1103 | Region *region = (Region*)((uint8_t*)ptr - sizeof(size_t)); |
| 1104 | |
| 1105 | // First attempt to resize the given region to avoid having to copy memory around |
| 1106 | if (acquire_and_attempt_region_resize(region, size + REGION_HEADER_SIZE)) { |
| 1107 | #ifdef __EMSCRIPTEN_TRACING__ |
| 1108 | emscripten_trace_record_reallocation(ptr, ptr, size); |
| 1109 | #endif |
| 1110 | return ptr; |
| 1111 | } |
| 1112 | |
| 1113 | // If resize failed, drop the old region and allocate a new region. Memory is not |
| 1114 | // copied over |
| 1115 | free(ptr); |
| 1116 | return emmalloc_memalign(alignment, size); |
| 1117 | } |
| 1118 | |
| 1119 | void *emmalloc_realloc(void *ptr, size_t size) { |
| 1120 | return emmalloc_aligned_realloc(ptr, MALLOC_ALIGNMENT, size); |
no test coverage detected