nlib
UnitHeap.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
17 #define INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
18 
19 #include "nn/nlib/Config.h"
20 
21 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
22 #undef NLIB_VIS_PUBLIC
23 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
24 #endif
25 
26 NLIB_NAMESPACE_BEGIN
27 namespace heap {
28 
30  public:
31  typedef void (*DestructorHandler)(void* start, void* end) NLIB_NOEXCEPT_FUNCPTR;
34  // Do not assert by GetAllocatedCount().
35  // Allow deallote without destroy.
36  if (handler_) {
37  (*handler_)(start_, end_);
38  }
39  }
40  errno_t Init(void* start, size_t size, DestructorHandler handler, size_t unit,
41  size_t algn, uint32_t heap_option) NLIB_NOEXCEPT;
42  void* Alloc() NLIB_NOEXCEPT;
43  errno_t Free(void* p) NLIB_NOEXCEPT;
44  size_t GetUnitSize() const NLIB_NOEXCEPT { return unit_size_; }
45  size_t GetUnitCount() const NLIB_NOEXCEPT { return unit_count_; }
46  size_t GetAllocatedCount() const NLIB_NOEXCEPT { return allocated_count_; }
47  void Dump() NLIB_NOEXCEPT;
48 
49  private:
50  struct Node {
51  Node* next;
52  };
53 
54  size_t unit_size_;
55  size_t baseunit_count_;
56  Node* free_list_;
57  size_t unit_count_;
58  size_t allocated_count_;
59 
60  uint32_t heap_option_;
61  uint8_t* start_;
62  uint8_t* end_;
63  DestructorHandler handler_;
64 };
65 
66 } // namespace heap
67 NLIB_NAMESPACE_END
68 
69 #if defined(_MSC_VER) && defined(nx_heap_EXPORTS)
70 #undef NLIB_VIS_PUBLIC
71 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
72 #endif
73 
74 #endif // INCLUDE_NN_NLIB_HEAP_UNITHEAP_H_
size_t GetUnitCount() const noexcept
Returns the number of regions that can be allocated from this heap.
Definition: UnitHeap.h:45
Heap for allocating and freeing fixed-size regions of memory. This is a so-called "pool-allocator...
Definition: UnitHeap.h:29
size_t GetAllocatedCount() const noexcept
Returns the number of regions that are currently allocated from this heap.
Definition: UnitHeap.h:46
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
size_t GetUnitSize() const noexcept
Returns the size of each region that to be allocated from this heap.
Definition: UnitHeap.h:44
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
A file that contains the configuration information for each development environment.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37