Skip to content

Commit 300841f

Browse files
committed
Replace memalloc / memfree by C++ new / delete
Signed-off-by: Stefan Weil <[email protected]>
1 parent ebea04e commit 300841f

File tree

4 files changed

+3
-26
lines changed

4 files changed

+3
-26
lines changed

cutil/freelist.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313

1414
#include <stdlib.h>
1515

16-
17-
// With improvements in OS memory allocators, internal memory management is
18-
// no longer required, so these functions all map to their malloc-family
19-
// equivalents.
20-
21-
22-
int *memalloc(int size) {
23-
return static_cast<int*>(malloc(static_cast<size_t>(size)));
24-
}
25-
2616
void memfree(void *element) {
2717
free(element);
2818
}

cutil/freelist.h

-10
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@
2626
#ifndef FREELIST_H
2727
#define FREELIST_H
2828

29-
/*----------------------------------------------------------------------
30-
I n c l u d e s
31-
----------------------------------------------------------------------*/
32-
#include <stdio.h>
33-
34-
/*----------------------------------------------------------------------
35-
F u n c t i o n s
36-
----------------------------------------------------------------------*/
37-
int *memalloc(int size);
38-
3929
void memfree(void *element);
4030

4131
#endif

dict/dawg.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "cutil.h"
3636
#include "dict.h"
3737
#include "emalloc.h"
38-
#include "freelist.h"
3938
#include "helpers.h"
4039
#include "strngs.h"
4140
#include "tesscallback.h"
@@ -191,7 +190,7 @@ void Dawg::init(int unicharset_size) {
191190
F u n c t i o n s f o r S q u i s h e d D a w g
192191
----------------------------------------------------------------------*/
193192

194-
SquishedDawg::~SquishedDawg() { memfree(edges_); }
193+
SquishedDawg::~SquishedDawg() { delete[] edges_; }
195194

196195
EDGE_REF SquishedDawg::edge_char_of(NODE_REF node,
197196
UNICHAR_ID unichar_id,
@@ -327,7 +326,7 @@ bool SquishedDawg::read_squished_dawg(TFile *file) {
327326
ASSERT_HOST(num_edges_ > 0); // DAWG should not be empty
328327
Dawg::init(unicharset_size);
329328

330-
edges_ = (EDGE_ARRAY) memalloc(sizeof(EDGE_RECORD) * num_edges_);
329+
edges_ = new EDGE_RECORD[num_edges_];
331330
if (file->FReadEndian(&edges_[0], sizeof(edges_[0]), num_edges_, swap) !=
332331
num_edges_)
333332
return false;

dict/trie.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "callcpp.h"
3535
#include "dawg.h"
3636
#include "dict.h"
37-
#include "freelist.h"
3837
#include "genericvector.h"
3938
#include "helpers.h"
4039
#include "kdpair.h"
@@ -547,8 +546,7 @@ SquishedDawg *Trie::trie_to_dawg() {
547546

548547
// Convert nodes_ vector into EDGE_ARRAY translating the next node references
549548
// in edges using node_ref_map. Empty nodes and backward edges are dropped.
550-
EDGE_ARRAY edge_array =
551-
(EDGE_ARRAY)memalloc(num_forward_edges * sizeof(EDGE_RECORD));
549+
EDGE_ARRAY edge_array = new EDGE_RECORD[num_forward_edges];
552550
EDGE_ARRAY edge_array_ptr = edge_array;
553551
for (i = 0; i < nodes_.size(); ++i) {
554552
TRIE_NODE_RECORD *node_ptr = nodes_[i];

0 commit comments

Comments
 (0)