summaryrefslogtreecommitdiff
path: root/benchmarks/CUDA/MUM/PoolMalloc.hh
blob: 8fb77337711fc0ea51f4bfa3a1f8d14501710380 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
////////////////////////////////////////////////////////////////////////////////
//! \file
//! \author Adam M Phillippy
//! \date 09/22/2006
//!
//! \brief PoolMalloc_t header file
//!
////////////////////////////////////////////////////////////////////////////////

#ifndef POOLMALLOC_HH
#define POOLMALLOC_HH

#include <cstdlib>

struct PoolNode_t;

//============================================================ PoolMalloc_t ====
/** \brief Class for allocating memory from a pool
 ** Manage memory in pools to speed up allocation of many short strings or
 ** arrays.
 **
 ** All of the arrays/strings allocated from a given PoolMalloc_t object
 ** should share the same lifetime, since they will all be free'd when the
 ** object is destroyed.
 **/

class PoolMalloc_t
{

public:
  /// Initialize the pool
  PoolMalloc_t();

  /// Free all of the memory associated with this object
  ~PoolMalloc_t();

  /// Explicitly free all of the memory associated with this object
  void pfree();

  /// Allocate an array from the pool
  void * pmalloc(size_t size);

  /// Copy a string using memory from the pool
  char * pstrdup(const char *s);

private:

  PoolNode_t *head_m;

};


#endif // POOLMALLOC_HH