forked from bartvdbraak/blender
Cycles: Fix issues with stack allocator in MSVC
Couple of issues here: - Was a bug in heap memory allocation when run out of allowed stack memory. - Debug MSVC was failing because it uses separate allocator for some sort of internal proxy thing, which seems to be unable to be using stack memory because allocator is being created in non-persistent stack location.
This commit is contained in:
parent
34f4c31692
commit
42fd1b9abe
@ -40,14 +40,17 @@ public:
|
|||||||
/* Allocator construction/destruction. */
|
/* Allocator construction/destruction. */
|
||||||
|
|
||||||
StackAllocator()
|
StackAllocator()
|
||||||
: pointer_(0) {}
|
: pointer_(0),
|
||||||
|
use_stack_(true) {}
|
||||||
|
|
||||||
StackAllocator(const StackAllocator&)
|
StackAllocator(const StackAllocator&)
|
||||||
: pointer_(0) {}
|
: pointer_(0),
|
||||||
|
use_stack_(true) {}
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
StackAllocator(const StackAllocator<SIZE, U>&)
|
StackAllocator(const StackAllocator<SIZE, U>&)
|
||||||
: pointer_(0) {}
|
: pointer_(0),
|
||||||
|
use_stack_(false) {}
|
||||||
|
|
||||||
/* Memory allocation/deallocation. */
|
/* Memory allocation/deallocation. */
|
||||||
|
|
||||||
@ -57,7 +60,7 @@ public:
|
|||||||
if(n == 0) {
|
if(n == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(pointer_ + n >= SIZE) {
|
if(pointer_ + n >= SIZE || use_stack_ == false) {
|
||||||
size_t size = n * sizeof(T);
|
size_t size = n * sizeof(T);
|
||||||
util_guarded_mem_alloc(size);
|
util_guarded_mem_alloc(size);
|
||||||
T *mem;
|
T *mem;
|
||||||
@ -69,6 +72,7 @@ public:
|
|||||||
if(mem == NULL) {
|
if(mem == NULL) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
return mem;
|
||||||
}
|
}
|
||||||
T *mem = &data_[pointer_];
|
T *mem = &data_[pointer_];
|
||||||
pointer_ += n;
|
pointer_ += n;
|
||||||
@ -157,6 +161,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int pointer_;
|
int pointer_;
|
||||||
|
bool use_stack_;
|
||||||
T data_[SIZE];
|
T data_[SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user