---
title: OSDictionary
framework: kernel
role: symbol
role_heading: Class
path: kernel/osdictionary
---

# OSDictionary

OSDictionary provides an associative store using strings for keys.

## Declaration

```occ
class OSDictionary : OSCollection
```

## Overview

Overview OSDictionary is a container for Libkern C++ objects (those derived from OSMetaClassBase, in particular OSObject). Storage and access are associative, based on string-valued keys (C string, OSString, or OSSymbol). When adding an object to an OSDictionary, you provide a string identifier, which can then used to retrieve that object or remove it from the dictionary. Setting an object with a key that already has an associated object replaces the original object. You must generally cast retrieved objects from OSObject to the desired class using OSDynamicCast. This macro returns the object cast to the desired class, or NULL if the object isn't derived from that class. When iterating an OSDictionary using OSCollectionIterator, the objects returned from getNextObject are dictionary keys (not the object values for those keys). You can use the keys to retrieve their associated object values. As with all Libkern collection classes, OSDictionary retains keys and objects added to it, and releases keys and objects removed from it (or replaced). An OSDictionary also grows as necessary to accommodate new key/value pairs, unlike Core Foundation collections (it does not, however, shrink). Note: OSDictionary currently uses a linear search algorithm, and is not designed for high-performance access of many values. It is intended as a simple associative-storage mechanism only. Use Restrictions With very few exceptions in the I/O Kit, all Libkern-based C++ classes, functions, and macros are unsafe to use in a primary interrupt context. Consult the I/O Kit documentation related to primary interrupts for more information. OSDictionary provides no concurrency protection; it's up to the usage context to provide any protection necessary. Some portions of the I/O Kit, such as IORegistryEntry, handle synchronization via defined member functions for setting properties.

## Topics

### Miscellaneous

- [copyCollection](kernel/osdictionary/1808081-copycollection.md)
- [ensureCapacity](kernel/osdictionary/1808087-ensurecapacity.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)

### Instance Methods

- [copyCollection](kernel/osdictionary/1412868-copycollection.md)
- [ensureCapacity](driverkit/osdictionary/ensurecapacity.md)
- [flushCollection](driverkit/osdictionary/flushcollection.md)
- [free](driverkit/osdictionary/free.md)
- [getCapacity](driverkit/osdictionary/getcapacity.md)
- [getCapacityIncrement](kernel/osdictionary/1412877-getcapacityincrement.md)
- [getCount](driverkit/osdictionary/getcount.md)
- [getMetaClass](kernel/osdictionary/1412876-getmetaclass.md)
- [getNextObjectForIterator](kernel/osdictionary/1412886-getnextobjectforiterator.md)
- [getObject](kernel/osdictionary/1412897-getobject.md)
- [getObject](driverkit/osdictionary/getobject-9ikoz.md)
- [getObject](driverkit/osdictionary/getobject-8k3ie.md)
- [initIterator](kernel/osdictionary/1412888-inititerator.md)
- [initWithCapacity](kernel/osdictionary/1412883-initwithcapacity.md)
- [initWithDictionary](kernel/osdictionary/1412866-initwithdictionary.md)
- [initWithObjects](kernel/osdictionary/1412860-initwithobjects.md)
- [initWithObjects](kernel/osdictionary/3516835-initwithobjects.md)
- [isEqualTo](driverkit/osdictionary/isequalto-2p9or.md)
- [isEqualTo](driverkit/osdictionary/isequalto-3c1k0.md)
- [isEqualTo](driverkit/osdictionary/isequalto-3kuk7.md)
- [iterateObjects](kernel/osdictionary/2967352-iterateobjects.md)
- [iterateObjects](kernel/osdictionary/3516836-iterateobjects.md)
- [iteratorSize](kernel/osdictionary/1412862-iteratorsize.md)
- [merge](driverkit/osdictionary/merge.md)
- [removeObject](kernel/osdictionary/1412855-removeobject.md)
- [removeObject](driverkit/osdictionary/removeobject-25qm5.md)
- [removeObject](driverkit/osdictionary/removeobject-156jh.md)
- [serialize](kernel/osdictionary/1412870-serialize.md)
- [setCapacityIncrement](kernel/osdictionary/1412885-setcapacityincrement.md)
- [setObject](kernel/osdictionary/1412895-setobject.md)
- [setObject](driverkit/osdictionary/setobject-9b4z0.md)
- [setObject](driverkit/osdictionary/setobject-7q0u2.md)
- [setObject](kernel/osdictionary/3567168-setobject.md)
- [setObject](kernel/osdictionary/3567169-setobject.md)
- [setObject](kernel/osdictionary/3567170-setobject.md)
- [setOptions](kernel/osdictionary/1412891-setoptions.md)

### Type Methods

- [withCapacity](driverkit/osdictionary/withcapacity.md)
- [withDictionary](driverkit/osdictionary/withdictionary.md)
- [withObjects](kernel/osdictionary/1412890-withobjects.md)
- [withObjects](driverkit/osdictionary/withobjects.md)

## Relationships

### Inherits From

- [OSCollection](kernel/oscollection.md)

## See Also

### Collections

- [OSArray](kernel/osarray.md)
- [OSSet](kernel/osset.md)
- [OSOrderedSet](kernel/osorderedset.md)
- [OSCollection](kernel/oscollection.md)
- [OSCollectionIterator](kernel/oscollectioniterator.md)
- [OSIterator](kernel/ositerator.md)
