mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
CtrlCore: Improved OutOfMemoryPanic
This commit is contained in:
parent
3dc229041e
commit
4947d30123
3 changed files with 13 additions and 11 deletions
|
|
@ -1,6 +1,4 @@
|
|||
void OutOfMemoryPanic();
|
||||
|
||||
void *SysAllocRaw(size_t size, size_t reqsize);
|
||||
void *SysAllocRaw(size_t size);
|
||||
void SysFreeRaw(void *ptr, size_t size);
|
||||
|
||||
const char *asString(int i);
|
||||
|
|
|
|||
|
|
@ -12,8 +12,12 @@ namespace Upp {
|
|||
|
||||
void OutOfMemoryPanic(size_t size)
|
||||
{
|
||||
char h[200];
|
||||
snprintf(h, 200, "Out of memory!\nU++ allocated memory: %d KB", MemoryUsedKb());
|
||||
char h[1024];
|
||||
snprintf(h, 200,
|
||||
"Out of memory!\n"
|
||||
"U++ allocated memory (including failed request): %zu KB\n"
|
||||
"System allocation request: %zu (0x%zx)\n",
|
||||
4 * (Heap::huge_4KB_count - Heap::free_4KB), size, size);
|
||||
Panic(h);
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +40,7 @@ int MemoryUsedKbMax()
|
|||
return int(4 * Heap::huge_4KB_count_max);
|
||||
}
|
||||
|
||||
void *SysAllocRaw(size_t size, size_t reqsize)
|
||||
void *SysAllocRaw(size_t size)
|
||||
{
|
||||
void *ptr = NULL;
|
||||
#ifdef PLATFORM_WIN32
|
||||
|
|
@ -68,12 +72,12 @@ void *MemoryAllocPermanent(size_t size)
|
|||
{
|
||||
Mutex::Lock __(Heap::mutex);
|
||||
if(size > 10000)
|
||||
return SysAllocRaw(size, size);
|
||||
return SysAllocRaw(size);
|
||||
static byte *ptr = NULL;
|
||||
static byte *limit = NULL;
|
||||
ASSERT(size < INT_MAX);
|
||||
if(!ptr || ptr + size >= limit) {
|
||||
ptr = (byte *)SysAllocRaw(16384, 16384);
|
||||
ptr = (byte *)SysAllocRaw(16384);
|
||||
limit = ptr + 16384;
|
||||
}
|
||||
void *p = ptr;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ EXITBLOCK {
|
|||
}
|
||||
#endif
|
||||
|
||||
size_t sKBLimit = INT_MAX;
|
||||
size_t sKBLimit = SIZE_MAX;
|
||||
|
||||
void MemoryLimitKb(int kb)
|
||||
{
|
||||
|
|
@ -80,7 +80,7 @@ void *Heap::HugeAlloc(size_t count) // count in 4kb pages
|
|||
|
||||
if(count > sys_block_limit) { // we are wasting 4KB to store just 4 bytes here, but this is n MB after all..
|
||||
LTIMING("SysAlloc");
|
||||
byte *sysblk = (byte *)SysAllocRaw((count + 1) * 4096, 0);
|
||||
byte *sysblk = (byte *)SysAllocRaw((count + 1) * 4096);
|
||||
BlkHeader *h = (BlkHeader *)(sysblk + 4096);
|
||||
h->size = 0;
|
||||
*((size_t *)sysblk) = count;
|
||||
|
|
@ -112,7 +112,7 @@ void *Heap::HugeAlloc(size_t count) // count in 4kb pages
|
|||
}
|
||||
|
||||
if(!FreeSmallEmpty(wcount, INT_MAX)) { // try to coalesce 4KB small free blocks back to huge storage
|
||||
void *ptr = SysAllocRaw(HPAGE * 4096, 0); // failed, add HPAGE from the system
|
||||
void *ptr = SysAllocRaw(HPAGE * 4096); // failed, add HPAGE from the system
|
||||
|
||||
HugePage *pg; // record in set of huge pages
|
||||
if(free_huge_pages) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue