mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 06:05:58 -06:00
UPP allocator now throwing bad_alloc
This commit is contained in:
parent
95e0b94fad
commit
181738a147
3 changed files with 15 additions and 8 deletions
|
|
@ -482,6 +482,10 @@ void AppExecute__(void (*app)())
|
|||
catch(ExitExc) {
|
||||
return;
|
||||
}
|
||||
catch(std::bad_alloc) {
|
||||
extern char out_of_memory_message[200];
|
||||
Panic(out_of_memory_message);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
|
|
|
|||
|
|
@ -10,13 +10,6 @@ namespace Upp {
|
|||
|
||||
#include "HeapImp.h"
|
||||
|
||||
void OutOfMemoryPanic(size_t size)
|
||||
{
|
||||
char h[200];
|
||||
snprintf(h, 200, "Out of memory!\nU++ allocated memory: %d KB", MemoryUsedKb());
|
||||
Panic(h);
|
||||
}
|
||||
|
||||
size_t Heap::huge_4KB_count;
|
||||
int Heap::free_4KB;
|
||||
size_t Heap::big_size;
|
||||
|
|
@ -26,6 +19,15 @@ size_t Heap::sys_count;
|
|||
size_t Heap::huge_chunks;
|
||||
size_t Heap::huge_4KB_count_max;
|
||||
|
||||
char out_of_memory_message[200];
|
||||
|
||||
void OutOfMemoryPanic(size_t size)
|
||||
{
|
||||
snprintf(out_of_memory_message, 200, "Out of memory!\nTrying to allocate: %d KB",
|
||||
(int)(min(size >> 10, (size_t)INT_MAX)));
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
int MemoryUsedKb()
|
||||
{
|
||||
return int(4 * (Heap::huge_4KB_count - Heap::free_4KB));
|
||||
|
|
|
|||
|
|
@ -130,7 +130,8 @@ void *Heap::HugeAlloc(size_t count) // count in 4kb pages
|
|||
AddChunk((BlkHeader *)ptr, HPAGE);
|
||||
}
|
||||
}
|
||||
Panic("Out of memory");
|
||||
void OutOfMemoryPanic(size_t size);
|
||||
OutOfMemoryPanic(count * 4096);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue