MCPcopy Create free account
hub / github.com/defold/defold / SetCapacity

Method SetCapacity

engine/dlib/src/jc/ringbuffer.h:130–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128
129template <typename T>
130void RingBuffer<T>::SetCapacity(uint32_t capacity)
131{
132 size_t old_capacity = Capacity();
133 if (capacity == old_capacity)
134 return;
135
136 if (capacity == 0)
137 {
138 Free();
139 return;
140 }
141
142 T* newbuffer = newbuffer = (T*)malloc(capacity*sizeof(T));
143
144 uint32_t size = Size();
145 if (size > capacity)
146 {
147 size = capacity;
148 }
149
150 // copy elements in reverse in order to keep the last inserted items
151 // E.g. resize from cap=6 to cap=4: 123456 -> 3456
152 for (int i = ((int)size)-1; i >= 0; --i)
153 {
154 newbuffer[i] = (*this)[(uint32_t)i];
155 }
156
157 T* tmp = m_Buffer;
158 m_Buffer = newbuffer;
159 free(tmp);
160
161 m_Tail = 0;
162 m_Head = size;
163 m_Max = capacity;
164 m_Full = capacity == size ? 1 : 0;
165}
166
167template <typename T>
168void RingBuffer<T>::OffsetCapacity(uint32_t grow)

Callers

nothing calls this directly

Calls 4

mallocFunction · 0.85
freeFunction · 0.85
FreeFunction · 0.50
SizeClass · 0.50

Tested by

no test coverage detected