Replace memalloc / memfree by C++ new / delete

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2017-05-01 17:26:23 +02:00
parent ebea04e67a
commit 300841f9a7
4 changed files with 3 additions and 26 deletions

View File

@ -13,16 +13,6 @@
#include <stdlib.h>
// With improvements in OS memory allocators, internal memory management is
// no longer required, so these functions all map to their malloc-family
// equivalents.
int *memalloc(int size) {
return static_cast<int*>(malloc(static_cast<size_t>(size)));
}
void memfree(void *element) {
free(element);
}

View File

@ -26,16 +26,6 @@
#ifndef FREELIST_H
#define FREELIST_H
/*----------------------------------------------------------------------
I n c l u d e s
----------------------------------------------------------------------*/
#include <stdio.h>
/*----------------------------------------------------------------------
F u n c t i o n s
----------------------------------------------------------------------*/
int *memalloc(int size);
void memfree(void *element);
#endif

View File

@ -35,7 +35,6 @@
#include "cutil.h"
#include "dict.h"
#include "emalloc.h"
#include "freelist.h"
#include "helpers.h"
#include "strngs.h"
#include "tesscallback.h"
@ -191,7 +190,7 @@ void Dawg::init(int unicharset_size) {
F u n c t i o n s f o r S q u i s h e d D a w g
----------------------------------------------------------------------*/
SquishedDawg::~SquishedDawg() { memfree(edges_); }
SquishedDawg::~SquishedDawg() { delete[] edges_; }
EDGE_REF SquishedDawg::edge_char_of(NODE_REF node,
UNICHAR_ID unichar_id,
@ -327,7 +326,7 @@ bool SquishedDawg::read_squished_dawg(TFile *file) {
ASSERT_HOST(num_edges_ > 0); // DAWG should not be empty
Dawg::init(unicharset_size);
edges_ = (EDGE_ARRAY) memalloc(sizeof(EDGE_RECORD) * num_edges_);
edges_ = new EDGE_RECORD[num_edges_];
if (file->FReadEndian(&edges_[0], sizeof(edges_[0]), num_edges_, swap) !=
num_edges_)
return false;

View File

@ -34,7 +34,6 @@
#include "callcpp.h"
#include "dawg.h"
#include "dict.h"
#include "freelist.h"
#include "genericvector.h"
#include "helpers.h"
#include "kdpair.h"
@ -547,8 +546,7 @@ SquishedDawg *Trie::trie_to_dawg() {
// Convert nodes_ vector into EDGE_ARRAY translating the next node references
// in edges using node_ref_map. Empty nodes and backward edges are dropped.
EDGE_ARRAY edge_array =
(EDGE_ARRAY)memalloc(num_forward_edges * sizeof(EDGE_RECORD));
EDGE_ARRAY edge_array = new EDGE_RECORD[num_forward_edges];
EDGE_ARRAY edge_array_ptr = edge_array;
for (i = 0; i < nodes_.size(); ++i) {
TRIE_NODE_RECORD *node_ptr = nodes_[i];