More documentation
This commit is contained in:
parent
43396b50cd
commit
cb0c3717fe
2 changed files with 64 additions and 4 deletions
|
|
@ -1,12 +1,54 @@
|
||||||
# heap.hpp & heap.cpp
|
# heap.hpp & heap.cpp
|
||||||
|
|
||||||
## Members
|
## Members
|
||||||
|
`char *const m_heap`: This is the pointer to the simulated heap which
|
||||||
|
collection occurs on. It's a byte array with a constant pointer.
|
||||||
|
|
||||||
|
`size_t m_size`: The size of bytes that has been allocated on the heap.
|
||||||
|
|
||||||
|
`inline static Heap *m_instance`: The singleton instance of Heap. Before
|
||||||
|
the heap is initialized this is initialized to the null pointer.
|
||||||
|
|
||||||
|
`uintptr_t *m_stack_top`: The address of the topmost stack frame which
|
||||||
|
serves as the stop for scanning the stack. Initialized as the null pointer
|
||||||
|
but assigned to the correct address in `Heap::init()`.
|
||||||
|
|
||||||
|
`bool m_profiler_enable`: The state of the profiler, `true` if the
|
||||||
|
profiler is enabled, `false` otherwise. It is initialized as `false`.
|
||||||
|
|
||||||
|
`std::vector<Chunk *> m_allocated_chunks`: Contains pointers to all
|
||||||
|
chunks that are allocated on the heap and can be reachable (if
|
||||||
|
a collection has been triggered previously).
|
||||||
|
|
||||||
|
`std::vector<Chunk *> m_freed_chunks`: Contains pointer to
|
||||||
|
chunks that have been freed, used to try and recycle chunks.
|
||||||
|
|
||||||
## Constructors
|
## Constructors
|
||||||
|
`Heap()`: Default constructor which guarantees to initialize
|
||||||
|
the `m_heap` pointer and the byte array. Declared private
|
||||||
|
in accordance with the singleton pattern.
|
||||||
|
|
||||||
## Destructors
|
## Destructors
|
||||||
|
`~Heap()`: Frees the `m_heap` byte array. Declared private
|
||||||
|
in accordance with the singleton pattern.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
`static void init()`: Initializes the heap singleton and the member
|
||||||
|
`m_instance`. Must be called before any calls to `alloc()`.
|
||||||
|
|
||||||
## Functions
|
`static void dispose()`: Disposes the heap singleton which frees
|
||||||
|
the heap. If the profiler is enabled the profiler is also disposed.
|
||||||
|
|
||||||
|
`static void *alloc(size_t size)`: Tries to allocate `size` amount
|
||||||
|
of bytes on the heap. The allocation is C-style, meaning `alloc()`
|
||||||
|
returns a `void *` similar to `malloc` and the user should cast
|
||||||
|
this pointer to an appropriate type. If this function is called with
|
||||||
|
the argument of 0, it will return the null pointer. This function can throw
|
||||||
|
runtime errors on two occasions. One if there is not enough memory
|
||||||
|
on the heap after a collection is triggered, it will throw a runtime
|
||||||
|
error with the message "Out of memory". The other occasion is when
|
||||||
|
a collection is triggered and the heap has not been initialized
|
||||||
|
properly by calling `init()`.
|
||||||
|
|
||||||
|
`static void set_profiler(bool mode)`: Enables or disables (`true`
|
||||||
|
or `false`) the profiler.
|
||||||
|
|
@ -1,12 +1,30 @@
|
||||||
# profiler.hpp & profiler.cpp
|
# profiler.hpp & profiler.cpp
|
||||||
|
|
||||||
## Members
|
## Members
|
||||||
|
`inline static Profiler *m_instance`: The pointer to the profiler
|
||||||
|
singleton instance.
|
||||||
|
|
||||||
|
`std::vector<GCEvent *> m_events`: A vector of events recorded
|
||||||
|
by the profiler. The contents are always sorted by time.
|
||||||
|
|
||||||
## Constructors
|
## Constructors
|
||||||
|
`Profiler()`: Default constructor, declared private because of
|
||||||
|
the singleton pattern.
|
||||||
|
|
||||||
## Destructors
|
## Destructors
|
||||||
|
`~Profiler()`: Default destructor, declared private because of
|
||||||
|
the singleton pattern. This destructor also deletes any events
|
||||||
|
that were recorded by the profiler to free memory.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
`static void record(GCEventType type)`: Records an event independent
|
||||||
|
of a size and a chunk (like `ProfilerDispose`).
|
||||||
|
|
||||||
## Functions
|
`static void record(GCEventType type, size_t size)`: Records an event independent
|
||||||
|
of a chunk but not a size (only `AllocStart`).
|
||||||
|
|
||||||
|
`static void record(GCEventType type, Chunk *chunk)`: Records an event independent
|
||||||
|
of a size but not a chunk (like `NewChunk`).
|
||||||
|
|
||||||
|
`static void dispose()`: Disposes the profiler by dumping a log file of all
|
||||||
|
events and deleting events to free memory.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue