diff --git a/GSCache.m b/GSCache.m index 5b40f3a..aebce31 100644 --- a/GSCache.m +++ b/GSCache.m @@ -51,6 +51,9 @@ #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4) #define class_getInstanceSize(isa) ((struct objc_class *)isa)->instance_size #endif + +#import "NSObject+GSExtensions.h" + #endif @interface GSCache (Threading) diff --git a/NSObject+GSExtensions.h b/NSObject+GSExtensions.h new file mode 100644 index 0000000..3ea6903 --- /dev/null +++ b/NSObject+GSExtensions.h @@ -0,0 +1,46 @@ +/** Declaration of extension methods for base additions + + Copyright (C) 2003-2010 Free Software Foundation, Inc. + + Written by: Richard Frith-Macdonald + and: Adam Fedor + + This file is part of the GNUstep Base Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. + +*/ + +#import + +@interface NSObject(MemoryFootprint) +/* This method returns the memory usage of the receiver, excluding any + * objects already present in the exclude table.
+ * The argument is a hash table configured to hold non-retained pointer + * objects and is used to inform the receiver that its size should not + * be counted again if it's already in the table.
+ * The NSObject implementation returns zero if the receiver is in the + * table, but otherwise adds itself to the table and returns its memory + * footprint (the sum of all of its instance variables, but not any + * memory pointed to by those variables).
+ * Subclasses should override this method by calling the superclass + * implementation, and either return the result (if it was zero) or + * return that value plus the sizes of any memory owned by the receiver + * (eg found by calling the same method on objects pointed to by the + * receiver's instance variables). + */ +- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude; +@end diff --git a/NSObject+GSExtensions.m b/NSObject+GSExtensions.m new file mode 100644 index 0000000..a4e38cb --- /dev/null +++ b/NSObject+GSExtensions.m @@ -0,0 +1,42 @@ +/* Implementation of extension methods to base additions + + Copyright (C) 2010 Free Software Foundation, Inc. + + Written by: Richard Frith-Macdonald + + This file is part of the GNUstep Base Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02111 USA. + +*/ + +#import + +@implementation NSObject (MemoryFootprint) ++ (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude +{ + return 0; +} +- (NSUInteger) sizeInBytesExcluding: (NSHashTable*)exclude +{ + if (0 == NSHashGet(exclude, self)) + { + NSHashInsert(exclude, self); + return class_getInstanceSize(object_getClass(self)); + } + return 0; +} +@end diff --git a/Performance.xcodeproj/project.pbxproj b/Performance.xcodeproj/project.pbxproj index 3e08c56..863d84e 100644 --- a/Performance.xcodeproj/project.pbxproj +++ b/Performance.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ 85872ECF1284CFC700B4601E /* GSTicker.h in Headers */ = {isa = PBXBuildFile; fileRef = 85872EBE1284CFC700B4601E /* GSTicker.h */; settings = {ATTRIBUTES = (Public, ); }; }; 85872ED01284CFC700B4601E /* GSTicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 85872EBF1284CFC700B4601E /* GSTicker.m */; }; 85872ED11284CFC700B4601E /* Performance.h in Headers */ = {isa = PBXBuildFile; fileRef = 85872EC01284CFC700B4601E /* Performance.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 85B7DBDC1C034FBA00AF3090 /* NSObject+GSExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 85B7DBDA1C034FBA00AF3090 /* NSObject+GSExtensions.h */; }; + 85B7DBDD1C034FBA00AF3090 /* NSObject+GSExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 85B7DBDB1C034FBA00AF3090 /* NSObject+GSExtensions.m */; }; 8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; }; 8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -52,6 +54,8 @@ 85872EC01284CFC700B4601E /* Performance.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Performance.h; sourceTree = ""; }; 8591FBED1A13422800923420 /* ChangeLog */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ChangeLog; sourceTree = ""; }; 85B560B3128C6E47003BAF08 /* Performance.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Performance.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 85B7DBDA1C034FBA00AF3090 /* NSObject+GSExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+GSExtensions.h"; sourceTree = ""; }; + 85B7DBDB1C034FBA00AF3090 /* NSObject+GSExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+GSExtensions.m"; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; D2F7E79907B2D74100F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; /* End PBXFileReference section */ @@ -110,6 +114,8 @@ 08FB77AEFE84172EC02AAC07 /* Classes */ = { isa = PBXGroup; children = ( + 85B7DBDA1C034FBA00AF3090 /* NSObject+GSExtensions.h */, + 85B7DBDB1C034FBA00AF3090 /* NSObject+GSExtensions.m */, 85872EB01284CFC700B4601E /* GSCache.h */, 85872EB11284CFC700B4601E /* GSCache.m */, 85872EB21284CFC700B4601E /* GSIndexedSkipList.h */, @@ -172,6 +178,7 @@ 85872ECD1284CFC700B4601E /* GSThroughput.h in Headers */, 85872ECF1284CFC700B4601E /* GSTicker.h in Headers */, 85872ED11284CFC700B4601E /* Performance.h in Headers */, + 85B7DBDC1C034FBA00AF3090 /* NSObject+GSExtensions.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -207,7 +214,6 @@ }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "Performance" */; compatibilityVersion = "Xcode 2.4"; - developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( English, @@ -249,6 +255,7 @@ 85872ECC1284CFC700B4601E /* GSThreadPool.m in Sources */, 85872ECE1284CFC700B4601E /* GSThroughput.m in Sources */, 85872ED01284CFC700B4601E /* GSTicker.m in Sources */, + 85B7DBDD1C034FBA00AF3090 /* NSObject+GSExtensions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -297,8 +304,8 @@ 1DEB91AF08733DA50010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1)"; - ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1 = "ppc i386"; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)"; + ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "x86_64 i386 ppc"; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; FRAMEWORK_VERSION = A; @@ -321,8 +328,7 @@ 1DEB91B208733DA50010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1)"; - ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1 = "ppc i386"; + ARCHS = "$(NATIVE_ARCH_ACTUAL)"; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO; @@ -336,8 +342,9 @@ 1DEB91B308733DA50010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1)"; - ARCHS_STANDARD_32_BIT_PRE_XCODE_3_1 = "ppc i386"; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1)"; + ARCHS_STANDARD_32_64_BIT_PRE_XCODE_3_1 = "x86_64 i386 ppc"; + GCC_MODEL_TUNING = ""; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; PREBINDING = NO;