[arrayfire] 249/284: Proper exception handling for memory manager
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:38 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.
commit 0039cdba798a675b3004217a37c004aaefe7a85f
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Wed Jan 27 15:55:04 2016 -0500
Proper exception handling for memory manager
---
src/backend/MemoryManager.cpp | 9 +++++----
src/backend/cpu/memory.cpp | 4 +++-
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/backend/MemoryManager.cpp b/src/backend/MemoryManager.cpp
index 03cefe7..8142628 100644
--- a/src/backend/MemoryManager.cpp
+++ b/src/backend/MemoryManager.cpp
@@ -145,12 +145,13 @@ void *MemoryManager::alloc(const size_t bytes)
}
// Perform garbage collection if memory can not be allocated
- ptr = this->nativeAlloc(alloc_bytes);
-
- if (!ptr) {
+ try {
+ ptr = this->nativeAlloc(alloc_bytes);
+ } catch (AfError &ex) {
+ // If out of memory, run garbage collect and try again
+ if (ex.getError() != AF_ERR_NO_MEM) throw;
this->garbageCollect();
ptr = this->nativeAlloc(alloc_bytes);
- if (!ptr) AF_ERROR("Can not allocate memory", AF_ERR_NO_MEM);
}
buffer_info info = {true, false, alloc_bytes};
diff --git a/src/backend/cpu/memory.cpp b/src/backend/cpu/memory.cpp
index 09a0e83..cf7e1ba 100644
--- a/src/backend/cpu/memory.cpp
+++ b/src/backend/cpu/memory.cpp
@@ -61,7 +61,9 @@ MemoryManager::MemoryManager() :
void *MemoryManager::nativeAlloc(const size_t bytes)
{
- return malloc(bytes);
+ void *ptr = malloc(bytes);
+ if (!ptr) AF_ERROR("Unable to allocate memory", AF_ERR_NO_MEM);
+ return ptr;
}
void MemoryManager::nativeFree(void *ptr)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list