MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / Reserve

Method Reserve

Include/XnArray.h:107–138  ·  view source on GitHub ↗

Reserves space in this array for the specified number of elements. This saves you re-allocations and data copies if you know the size in advance. **/

Source from the content-addressed store, hash-verified

105 /** Reserves space in this array for the specified number of elements.
106 This saves you re-allocations and data copies if you know the size in advance. **/
107 XnStatus Reserve(XnUInt32 nReservedSize)
108 {
109 if (nReservedSize > m_nAllocatedSize)
110 {
111 //Calculate next power of 2 after nReservedSize
112 nReservedSize--;
113 nReservedSize = (nReservedSize >> 1) | nReservedSize;
114 nReservedSize = (nReservedSize >> 2) | nReservedSize;
115 nReservedSize = (nReservedSize >> 4) | nReservedSize;
116 nReservedSize = (nReservedSize >> 8) | nReservedSize;
117 nReservedSize = (nReservedSize >> 16) | nReservedSize;
118 nReservedSize++; // nReservedSize is now the next power of 2.
119
120 //Allocate new data
121 T* pNewData = XN_NEW_ARR(T, nReservedSize);
122 XN_VALIDATE_ALLOC_PTR(pNewData);
123
124 //Copy old data into new data
125 for (XnUInt32 i = 0; i < m_nSize; i++)
126 {
127 pNewData[i] = m_pData[i];
128 }
129
130 //Delete old data
131 XN_DELETE_ARR(m_pData);
132
133 //Point to new data
134 m_pData = pNewData;
135 m_nAllocatedSize = nReservedSize;
136 }
137 return XN_STATUS_OK;
138 }
139
140 /** @returns TRUE if this array is empty, FALSE otherwise. **/
141 XnBool IsEmpty() const

Callers 2

XnVideoStreamMethod · 0.45
EnumerateMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected