MCPcopy Create free account
hub / github.com/EricPengShuai/Interview / expand

Method expand

base_code/template.cpp:279–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277 Alloc _allocator;
278
279 void expand()
280 {
281 int size = _end - _first;
282 T *ptmp = _allocator.allocate(2 * size); // 分配 2*size 大小内存
283 int len = _last - _first;
284 for (int i = 0; i < size; ++ i) { // 构造 size 个有效的T对象
285 _allocator.construct(ptmp + i, _first[i]);
286 }
287
288 // 先析构再free
289 for (T *p = _first; p != _last; ++ p) {
290 _allocator.destroy(p);
291 }
292 _allocator.deallocate(_first);
293 _first = ptmp;
294 _last = _first + size;
295 _end = _first + 2 * size;
296 }
297};
298
299/* 测试类 */

Callers

nothing calls this directly

Calls 4

allocateMethod · 0.80
constructMethod · 0.80
destroyMethod · 0.80
deallocateMethod · 0.80

Tested by

no test coverage detected