Panda3D
Loading...
Searching...
No Matches
dcPackData.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file dcPackData.cxx
10 * @author drose
11 * @date 2004-06-15
12 */
13
14#include "dcPackData.h"
15
16static const size_t extra_size = 50;
17
18/**
19 * Ensures that the buffer has at least size bytes, and sets the _used_length
20 * to the indicated value; grows the buffer if it does not.
21 */
22void DCPackData::
23set_used_length(size_t size) {
24 if (size > _allocated_size) {
25 _allocated_size = size + size + extra_size;
26 char *new_buf = new char[_allocated_size];
27 if (_used_length > 0) {
28 memcpy(new_buf, _buffer, _used_length);
29 }
30 if (_buffer != nullptr) {
31 delete[] _buffer;
32 }
33 _buffer = new_buf;
34 }
35
36 _used_length = size;
37}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.