diff --git a/uppsrc/Core/HeapImp.h b/uppsrc/Core/HeapImp.h index 12128ae7a..2cebe43d8 100644 --- a/uppsrc/Core/HeapImp.h +++ b/uppsrc/Core/HeapImp.h @@ -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); diff --git a/uppsrc/Core/heaputil.cpp b/uppsrc/Core/heaputil.cpp index 99eaa48ac..74aa47011 100644 --- a/uppsrc/Core/heaputil.cpp +++ b/uppsrc/Core/heaputil.cpp @@ -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; diff --git a/uppsrc/Core/hheap.cpp b/uppsrc/Core/hheap.cpp index b98870332..d0d2760c0 100644 --- a/uppsrc/Core/hheap.cpp +++ b/uppsrc/Core/hheap.cpp @@ -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) {