Core: Vector now supports max 2G items (exactly)

git-svn-id: svn://ultimatepp.org/upp/trunk@9289 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2015-12-14 17:42:13 +00:00
parent 08302fe6e3
commit e9a75eef5f
3 changed files with 21 additions and 5 deletions

View file

@ -186,7 +186,7 @@ class InVector<T>::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; }

View file

@ -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) {

View file

@ -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