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