Skip to content

Commit 34013c0

Browse files
author
Jaime Arteaga
committed
Minor refactoring to allocateSystemMemory and selectHeap
Change-Id: I2cf3917d56773535b7a06a7d091c14c4320ef734 Signed-off-by: Jaime Arteaga <[email protected]>
1 parent ce8d24d commit 34013c0

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

runtime/memory_manager/memory_manager.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,25 @@ void *MemoryManager::allocateSystemMemory(size_t size, size_t alignment) {
5353
constexpr size_t minAlignment = 16;
5454
alignment = std::max(alignment, minAlignment);
5555
auto restrictions = getAlignedMallocRestrictions();
56-
void *ptr = nullptr;
56+
void *ptr = alignedMallocWrapper(size, alignment);
5757

58-
ptr = alignedMallocWrapper(size, alignment);
59-
if (restrictions == nullptr) {
58+
if (restrictions == nullptr || restrictions->minAddress == 0) {
6059
return ptr;
61-
} else if (restrictions->minAddress == 0) {
62-
return ptr;
63-
} else {
64-
if (restrictions->minAddress > reinterpret_cast<uintptr_t>(ptr) && ptr != nullptr) {
65-
StackVec<void *, 100> invalidMemVector;
66-
invalidMemVector.push_back(ptr);
67-
do {
68-
ptr = alignedMallocWrapper(size, alignment);
69-
if (restrictions->minAddress > reinterpret_cast<uintptr_t>(ptr) && ptr != nullptr) {
70-
invalidMemVector.push_back(ptr);
71-
} else {
72-
break;
73-
}
74-
} while (1);
75-
for (auto &it : invalidMemVector) {
76-
alignedFreeWrapper(it);
60+
}
61+
62+
if (restrictions->minAddress > reinterpret_cast<uintptr_t>(ptr) && ptr != nullptr) {
63+
StackVec<void *, 100> invalidMemVector;
64+
invalidMemVector.push_back(ptr);
65+
do {
66+
ptr = alignedMallocWrapper(size, alignment);
67+
if (restrictions->minAddress > reinterpret_cast<uintptr_t>(ptr) && ptr != nullptr) {
68+
invalidMemVector.push_back(ptr);
69+
} else {
70+
break;
7771
}
72+
} while (1);
73+
for (auto &it : invalidMemVector) {
74+
alignedFreeWrapper(it);
7875
}
7976
}
8077

@@ -411,7 +408,8 @@ HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, bool h
411408
if (allocation) {
412409
if (useInternal32BitAllocator(allocation->getAllocationType())) {
413410
return internalHeapIndex;
414-
} else if (allocation->is32BitAllocation()) {
411+
}
412+
if (allocation->is32BitAllocation()) {
415413
return HeapIndex::HEAP_EXTERNAL;
416414
}
417415
}

0 commit comments

Comments
 (0)