00001 // Filename: dcPackData.cxx 00002 // Created by: drose (15Jun04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "dcPackData.h" 00016 00017 static const size_t extra_size = 50; 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: DCPackData::set_used_length 00021 // Access: Private 00022 // Description: Ensures that the buffer has at least size bytes, and 00023 // sets the _used_length to the indicated value; grows 00024 // the buffer if it does not. 00025 //////////////////////////////////////////////////////////////////// 00026 void DCPackData:: 00027 set_used_length(size_t size) { 00028 if (size > _allocated_size) { 00029 _allocated_size = size + size + extra_size; 00030 char *new_buf = new char[_allocated_size]; 00031 if (_used_length > 0) { 00032 memcpy(new_buf, _buffer, _used_length); 00033 } 00034 if (_buffer != NULL) { 00035 delete[] _buffer; 00036 } 00037 _buffer = new_buf; 00038 } 00039 00040 _used_length = size; 00041 }