Skip to content

Commit

Permalink
Merge pull request #860 from stweil/malloc
Browse files Browse the repository at this point in the history
Replace memalloc / memfree by C++ new / delete
  • Loading branch information
zdenop authored May 1, 2017
2 parents ebea04e + 300841f commit b9dff16
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 26 deletions.
10 changes: 0 additions & 10 deletions cutil/freelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 0 additions & 10 deletions cutil/freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions dict/dawg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions dict/trie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit b9dff16

Please sign in to comment.