Skip to content

Commit 7239dd6

Browse files
committed
[Runtime] Fix swift_slowAlloc to respect its alignMask parameter.
Instead of calling malloc, call AlignedAlloc. That calls posix_memalign on platforms where it's available. The man page cautions to use it judiciously, but Apple OSes and Linux implement it to call through to malloc when the alignment is suitable. Presumably/hopefully other OSes do the same. rdar://problem/22975669
1 parent e43ff71 commit 7239dd6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

stdlib/public/runtime/Heap.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@
2323
using namespace swift;
2424

2525
void *swift::swift_slowAlloc(size_t size, size_t alignMask) {
26-
// FIXME: use posix_memalign if alignMask is larger than the system guarantee.
27-
void *p = malloc(size);
26+
void *p = AlignedAlloc(size, alignMask + 1);
2827
if (!p) swift::crash("Could not allocate memory.");
2928
return p;
3029
}
3130

3231
void swift::swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask) {
33-
free(ptr);
32+
AlignedFree(ptr);
3433
}

0 commit comments

Comments
 (0)