improve reportingn of memory usage

This commit is contained in:
Richard Frith-Macdonald 2019-06-11 14:07:10 +01:00
parent 42b404c586
commit 3f7d54a33f
18 changed files with 395 additions and 267 deletions

View file

@ -73,6 +73,21 @@ static Class GSInlineArrayClass;
@implementation GSArray
+ (NSUInteger) contentSizeOf: (NSObject*)obj
declaredIn: (Class)cls
excluding: (NSHashTable*)exclude
{
GSArray *a = (GSArray*)obj;
NSUInteger size = a->_count * sizeof(id);
NSUInteger index = a->_count;
while (index-- > 0)
{
size += [a->_contents_array[index] sizeInBytesExcluding: exclude];
}
return size;
}
- (void) _raiseRangeExceptionWithIndex: (NSUInteger)index from: (SEL)sel
{
NSDictionary *info;
@ -421,6 +436,21 @@ static Class GSInlineArrayClass;
@implementation GSMutableArray
+ (NSUInteger) contentSizeOf: (NSObject*)obj
declaredIn: (Class)cls
excluding: (NSHashTable*)exclude
{
GSMutableArray *a = (GSMutableArray*)obj;
NSUInteger size = a->_capacity * sizeof(id);
NSUInteger index = a->_count;
while (index-- > 0)
{
size += [a->_contents_array[index] sizeInBytesExcluding: exclude];
}
return size;
}
+ (void) initialize
{
if (self == [GSMutableArray class])
@ -938,22 +968,6 @@ static Class GSInlineArrayClass;
return count;
}
- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude
{
NSUInteger size = GSPrivateMemorySize(self, exclude);
if (size > 0)
{
NSUInteger count = _count;
size += _capacity*sizeof(void*);
while (count-- > 0)
{
size += [_contents_array[count] sizeInBytesExcluding: exclude];
}
}
return size;
}
@end