summaryrefslogtreecommitdiff
path: root/src/NIS/NIS_Allocator.cxx
blob: 0f7cb0c48aff48e448a9277fb95e0b415dffdb92 (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
// File:      NIS_Allocator.cpp
// Created:   22.10.10 17:35
// Author:    Alexander GRIGORIEV
// Copyright: Open Cascade 2010

#include <NIS_Allocator.hxx>

IMPLEMENT_STANDARD_HANDLE  (NIS_Allocator, NCollection_IncAllocator)
IMPLEMENT_STANDARD_RTTIEXT (NIS_Allocator, NCollection_IncAllocator)

//=======================================================================
//function : NIS_Allocator
//purpose  : 
//=======================================================================

NIS_Allocator::NIS_Allocator (const size_t theBlockSize)
  : NCollection_IncAllocator  (theBlockSize),
    myNAllocated              (0),
    myNFreed                  (0)
{}

//=======================================================================
//function : ResetCounters
//purpose  : 
//=======================================================================

void NIS_Allocator::ResetCounters ()
{
  myNAllocated = 0;
  myNFreed = 0;
}

//=======================================================================
//function : Allocate
//purpose  : 
//=======================================================================

void* NIS_Allocator::Allocate (const size_t size)
{
  size_t* pResult = reinterpret_cast<size_t*>
    (NCollection_IncAllocator::Allocate(size + sizeof(size_t)));
  pResult[0] = size;
  myNAllocated += size;
  return &pResult[1];
}

//=======================================================================
//function : Free
//purpose  : 
//=======================================================================

void NIS_Allocator::Free (void *anAddress)
{
  if (anAddress) {
    size_t* pAddress = reinterpret_cast<size_t*>(anAddress) - 1;
    myNFreed += pAddress[0];
    NCollection_IncAllocator::Free(pAddress);
  }
}