---
title: ensureCapacity
framework: kernel
role: pseudoSymbol
path: kernel/osdictionary/1808087-ensurecapacity
---

# ensureCapacity

Ensures the dictionary has enough space to store the requested number of key/object pairs.

## Declaration

```occ
virtual unsigned int ensureCapacity(
 unsigned intnewCapacity); 
```

## Parameters

- `newCapacity`: The total number of key/object pairs the dictionary should be able to store.

## Return Value

Return Value The new capacity of the dictionary, which may be different from the number requested (if smaller, reallocation of storage failed).

## Overview

Overview This function immediately resizes the dictionary, if necessary, to accommodate at least newCapacity key/object pairs. If newCapacity is not greater than the current capacity, or if an allocation error occurs, the original capacity is returned. There is no way to reduce the capacity of an OSDictionary.

## See Also

### Miscellaneous

- [copyCollection](kernel/osdictionary/1808081-copycollection.md)
- [flushCollection](kernel/osdictionary/1808092-flushcollection.md)
- [free](kernel/osdictionary/1808101-free.md)
- [getCapacity](kernel/osdictionary/1808107-getcapacity.md)
- [getCapacityIncrement](kernel/osdictionary/1808116-getcapacityincrement.md)
- [getCount](kernel/osdictionary/1808124-getcount.md)
- [getObject](kernel/osdictionary/1808133-getobject.md)
- [getObject(const OSString *)](kernel/osdictionary/1808139-getobject.md)
- [getObject(const OSSymbol *)](kernel/osdictionary/1808148-getobject.md)
- [initWithCapacity](kernel/osdictionary/1808159-initwithcapacity.md)
- [initWithDictionary](kernel/osdictionary/1808166-initwithdictionary.md)
- [initWithObjects(const OSObject *, const OSString *, unsigned int, unsigned int)](kernel/osdictionary/1808177-initwithobjects.md)
- [initWithObjects(const OSObject *, const OSSymbol *, unsigned int, unsigned int)](kernel/osdictionary/1808181-initwithobjects.md)
- [isEqualTo](kernel/osdictionary/1808187-isequalto.md)
- [isEqualTo(const OSDictionary *)](kernel/osdictionary/1808191-isequalto.md)
- [isEqualTo(const OSDictionary *, const OSCollection *)](kernel/osdictionary/1808194-isequalto.md)
- [merge](kernel/osdictionary/1808198-merge.md)
- [removeObject](kernel/osdictionary/1808205-removeobject.md)
- [removeObject(const OSString *)](kernel/osdictionary/1808207-removeobject.md)
- [removeObject(const OSSymbol *)](kernel/osdictionary/1808209-removeobject.md)
- [serialize](kernel/osdictionary/1808214-serialize.md)
- [setCapacityIncrement](kernel/osdictionary/1808218-setcapacityincrement.md)
- [setObject](kernel/osdictionary/1808220-setobject.md)
- [setObject(const OSString *, const OSMetaClassBase *)](kernel/osdictionary/1808224-setobject.md)
- [setObject(const OSSymbol *, const OSMetaClassBase *)](kernel/osdictionary/1808227-setobject.md)
- [withCapacity](kernel/osdictionary/1808230-withcapacity.md)
- [withDictionary](kernel/osdictionary/1808234-withdictionary.md)
- [withObjects(const OSObject *, const OSString *, unsigned int, unsigned int)](kernel/osdictionary/1808237-withobjects.md)
- [withObjects(const OSObject *, const OSSymbol *, unsigned int, unsigned int)](kernel/osdictionary/1808240-withobjects.md)
