diff --git a/uppsrc/Core/InVector.h b/uppsrc/Core/InVector.h index f24fe1c48..6a8630c66 100644 --- a/uppsrc/Core/InVector.h +++ b/uppsrc/Core/InVector.h @@ -186,7 +186,7 @@ class InVector::ConstIterator { void PrevBlk(); public: - force_inline int GetIndex() const { return ptr - begin + offset; } + force_inline int GetIndex() const { return int(ptr - begin) + offset; } force_inline ConstIterator& operator++() { ASSERT(ptr); if(++ptr == end) NextBlk(); return *this; } force_inline ConstIterator& operator--() { ASSERT(ptr); if(ptr == begin) PrevBlk(); --ptr; return *this; } diff --git a/uppsrc/Core/Log.cpp b/uppsrc/Core/Log.cpp index 2fea1edf1..d66c4ca21 100644 --- a/uppsrc/Core/Log.cpp +++ b/uppsrc/Core/Log.cpp @@ -326,6 +326,21 @@ String AsString(const MemoryProfile& mem) return text; } +int64 GetAllocatedBytes(const MemoryProfile& mem) +{ + int64 asize = 0; +#ifdef UPP_HEAP + for(int i = 0; i < 1024; i++) + if(mem.allocated[i]) { + int sz = 4 * i; + asize += mem.allocated[i] * sz; + } + asize += mem.large_total; + asize += mem.big_size; +#endif + return asize; +} + #ifdef flagCHECKINIT void InitBlockBegin__(const char *fn, int line) { diff --git a/uppsrc/Core/Vcont.cpp b/uppsrc/Core/Vcont.cpp index 8e212c8c3..bd901633b 100644 --- a/uppsrc/Core/Vcont.cpp +++ b/uppsrc/Core/Vcont.cpp @@ -33,8 +33,7 @@ void VectorReAlloc_(void *v_, int newalloc, int sizeofT) size_t sz0 = (size_t)newalloc * sizeofT; size_t sz = sz0; void *newvector = newalloc ? MemoryAllocSz(sz) : NULL; -// v->alloc = /*(sz - sz0) / sizeofT + */newalloc; //Benchmark... - v->alloc = (int)((sz - sz0) / sizeofT + newalloc); //Benchmark... + v->alloc = newalloc == INT_MAX ? INT_MAX : (int)((sz - sz0) / sizeofT + newalloc); if(v->vector) memcpy(newvector, v->vector, (size_t)v->items * sizeofT); v->vector = newvector; @@ -51,10 +50,12 @@ void VectorReAllocF_(void *v_, int newalloc, int sizeofT) void VectorGrow_(void *v_, int sizeofT) { Vector_ *v = (Vector_*)v_; + if(v->alloc == INT_MAX) + Panic("Too many items in container!"); #ifdef _DEBUG - VectorReAlloc_(v, max(v->alloc + 1, 2 * v->alloc), sizeofT); + VectorReAlloc_(v, max(v->alloc + 1, v->alloc >= INT_MAX / 2 ? INT_MAX : 2 * v->alloc), sizeofT); #else - VectorReAlloc_(v, max(v->alloc + 1, int(v->alloc + ((unsigned)v->alloc >> 1))), sizeofT); + VectorReAlloc_(v, max(v->alloc + 1, v->alloc >= int((int64)2 * INT_MAX / 3) ? INT_MAX : v->alloc + (v->alloc >> 1)), sizeofT); // VectorReAlloc_(v, max(v->alloc + 1, max(2 * v->alloc, 16 / sizeofT)), sizeofT); // VectorReAlloc_(v, max(v->alloc + 1, 2 * v->alloc), sizeofT); #endif