1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#include "Prerequisites/BsPrerequisitesUtil.h"
4#include "Allocators/BsStackAlloc.h"
5
6namespace bs
7{
8 BS_THREADLOCAL MemStackInternal<1024 * 1024>* MemStack::ThreadMemStack = nullptr;
9
10 void MemStack::beginThread()
11 {
12 if(ThreadMemStack != nullptr)
13 endThread();
14
15 ThreadMemStack = bs_new<MemStackInternal<1024 * 1024>>();
16 }
17
18 void MemStack::endThread()
19 {
20 if(ThreadMemStack != nullptr)
21 {
22 bs_delete(ThreadMemStack);
23 ThreadMemStack = nullptr;
24 }
25 }
26
27 UINT8* MemStack::alloc(UINT32 numBytes)
28 {
29 assert(ThreadMemStack != nullptr && "Stack allocation failed. Did you call beginThread?");
30
31 return ThreadMemStack->alloc(numBytes);
32 }
33
34 void MemStack::deallocLast(UINT8* data)
35 {
36 assert(ThreadMemStack != nullptr && "Stack deallocation failed. Did you call beginThread?");
37
38 ThreadMemStack->dealloc(data);
39 }
40}
41