summaryrefslogtreecommitdiffstats
path: root/db/mork/src/orkinHeap.cpp
blob: 4a309a154f9dc6ad2dc0434993b1dbb35a4006b0 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-  */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef _MDB_
#include "mdb.h"
#endif

#ifndef _MORK_
#include "mork.h"
#endif

#ifndef _ORKINHEAP_
#include "orkinHeap.h"
#endif

#ifndef _MORKENV_
#include "morkEnv.h"
#endif

#include "nsIMemoryReporter.h"

#include <stdlib.h>

//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789


orkinHeap::orkinHeap() // does nothing
  : mUsedSize(0)
{
}

/*virtual*/
orkinHeap::~orkinHeap() // does nothing
{
}

MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MorkSizeOfOnAlloc)
MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MorkSizeOfOnFree)

// { ===== begin nsIMdbHeap methods =====
/*virtual*/ nsresult
orkinHeap::Alloc(nsIMdbEnv* mev, // allocate a piece of memory
  mdb_size inSize,  // requested size of new memory block
  void** outBlock)  // memory block of inSize bytes, or nil
{

  MORK_USED_1(mev);
  nsresult outErr = NS_OK;
  void* block = malloc(inSize);
  if ( !block )
    outErr = morkEnv_kOutOfMemoryError;
  else
    mUsedSize += MorkSizeOfOnAlloc(block);

  MORK_ASSERT(outBlock);
  if ( outBlock )
    *outBlock = block;
  return outErr;
}

/*virtual*/ nsresult
orkinHeap::Free(nsIMdbEnv* mev, // free block allocated earlier by Alloc()
  void* inBlock)
{
  MORK_USED_1(mev);
  MORK_ASSERT(inBlock);
  if ( inBlock )
  {
    mUsedSize -= MorkSizeOfOnFree(inBlock);
    free(inBlock);
  }
  return NS_OK;
}

size_t
orkinHeap::GetUsedSize()
{
  return mUsedSize;
}
// } ===== end nsIMdbHeap methods =====

//3456789_123456789_123456789_123456789_123456789_123456789_123456789_123456789