|
|
|
@ -9,8 +9,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License. */
|
|
|
|
|
|
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
#include "paddle/fluid/inference/api/paddle_inference_api.h"
|
|
|
|
|
#include "paddle/fluid/platform/enforce.h"
|
|
|
|
|
|
|
|
|
|
namespace paddle {
|
|
|
|
|
|
|
|
|
@ -64,13 +64,15 @@ PaddleBuf& PaddleBuf::operator=(PaddleBuf&& other) {
|
|
|
|
|
|
|
|
|
|
void PaddleBuf::Resize(size_t length) {
|
|
|
|
|
// Only the owned memory can be reset, the external memory can't be changed.
|
|
|
|
|
if (length_ == length) return;
|
|
|
|
|
if (length_ >= length) return;
|
|
|
|
|
if (memory_owned_) {
|
|
|
|
|
Free();
|
|
|
|
|
data_ = malloc(length);
|
|
|
|
|
length_ = length;
|
|
|
|
|
memory_owned_ = true;
|
|
|
|
|
} else {
|
|
|
|
|
PADDLE_THROW("The memory is allocated externally, can not Resized");
|
|
|
|
|
}
|
|
|
|
|
data_ = new char[length];
|
|
|
|
|
length_ = length;
|
|
|
|
|
memory_owned_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaddleBuf::Reset(void* data, size_t length) {
|
|
|
|
@ -82,8 +84,8 @@ void PaddleBuf::Reset(void* data, size_t length) {
|
|
|
|
|
|
|
|
|
|
void PaddleBuf::Free() {
|
|
|
|
|
if (memory_owned_ && data_) {
|
|
|
|
|
assert(length_ > 0);
|
|
|
|
|
delete[] static_cast<char*>(data_);
|
|
|
|
|
PADDLE_ENFORCE_GT(length_, 0);
|
|
|
|
|
free(static_cast<char*>(data_));
|
|
|
|
|
data_ = nullptr;
|
|
|
|
|
length_ = 0;
|
|
|
|
|
}
|
|
|
|
|