Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -57,10 +57,19 @@ * @param itemSize The size of a single element in the OFDataArray * @return A new autoreleased OFDataArray */ + (instancetype)dataArrayWithItemSize: (size_t)itemSize; +/*! + * @brief Creates a new OFDataArray with enough memory to hold the specified + * number of items which all have an item size of 1. + * + * @param capacity The initial capacity for the OFDataArray + * @return A new autoreleased OFDataArray + */ ++ (instancetype)dataArrayWithCapacity: (size_t)capacity; + /*! * @brief Creates a new OFDataArray with enough memory to hold the specified * number of items which all have the same specified size. * * @param itemSize The size of a single element in the OFDataArray @@ -113,10 +122,19 @@ * @param itemSize The size of a single element in the OFDataArray * @return An initialized OFDataArray */ - initWithItemSize: (size_t)itemSize; +/*! + * @brief Initializes an already allocated OFDataArray with enough memory to + * hold the specified number of items which all have an item size of 1. + * + * @param capacity The initial capacity for the OFDataArray + * @return An initialized OFDataArray + */ +- initWithCapacity: (size_t)capacity; + /*! * @brief Initializes an already allocated OFDataArray with enough memory to * hold the specified number of items which all have the same specified * size. * Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -62,10 +62,15 @@ + (instancetype)dataArrayWithItemSize: (size_t)itemSize { return [[[self alloc] initWithItemSize: itemSize] autorelease]; } + ++ (instancetype)dataArrayWithCapacity: (size_t)capacity +{ + return [[[self alloc] initWithCapacity: capacity] autorelease]; +} + (instancetype)dataArrayWithItemSize: (size_t)itemSize capacity: (size_t)capacity { return [[[self alloc] initWithItemSize: itemSize @@ -102,10 +107,16 @@ - initWithItemSize: (size_t)itemSize { return [self initWithItemSize: itemSize capacity: 0]; } + +- initWithCapacity: (size_t)capacity +{ + return [self initWithItemSize: 1 + capacity: capacity]; +} - initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { self = [super init];