strngs: Replace alloc_mem, free_mem by standard functions

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-06-25 14:31:48 +02:00
parent 8953f4149f
commit 20e243d5c9

View File

@ -19,10 +19,10 @@
#include "strngs.h"
#include <cassert> // for assert
#include <cstdlib> // for malloc, free
#include "errcode.h" // for ASSERT_HOST
#include "genericvector.h" // for GenericVector
#include "helpers.h" // for ReverseN
#include "memry.h" // for alloc_string, free_string
#include "serialis.h" // for TFile
using tesseract::TFile;
@ -51,7 +51,7 @@ const int kMaxDoubleSize = 16;
const int kMinCapacity = 16;
char* STRING::AllocData(int used, int capacity) {
data_ = (STRING_HEADER *)alloc_string(capacity + sizeof(STRING_HEADER));
data_ = (STRING_HEADER *)malloc(capacity + sizeof(STRING_HEADER));
// header is the metadata for this memory block
STRING_HEADER* header = GetHeader();
@ -61,7 +61,8 @@ char* STRING::AllocData(int used, int capacity) {
}
void STRING::DiscardData() {
free_string((char *)data_);
free(data_);
data_ = nullptr;
}
// This is a private method; ensure FixHeader is called (or used_ is well defined)
@ -78,7 +79,7 @@ char* STRING::ensure_cstr(int32_t min_capacity) {
min_capacity = 2 * orig_header->capacity_;
int alloc = sizeof(STRING_HEADER) + min_capacity;
STRING_HEADER* new_header = (STRING_HEADER*)(alloc_string(alloc));
STRING_HEADER* new_header = (STRING_HEADER*)(malloc(alloc));
memcpy(&new_header[1], GetCStr(), orig_header->used_);
new_header->capacity_ = min_capacity;