<commit_before>// Copyright(c) 2016 <NAME>
// Distributed under the MIT License (See accompanying file LICENSE.md file or copy at http://opensource.org/licenses/MIT).
#pragma once
#include "memory/pch.h"
#include "memory/allocator/coLocalAllocator.h"
#include "debug/log/coAssert.h"
#include "debug/log/coLog.h"

coLocalAllocator::coLocalAllocator(coUint32 _maxStackAlloc)
	: stackBuffer(nullptr)
	, stackAllocated(0)
	, maxStackAlloc(_maxStackAlloc)
{
	coASSERT(maxStackAlloc < 16 * 1024); // safety
	stackBuffer = static_cast<coByte*>(::alloca(maxStackAlloc));
	coASSERT(stackBuffer);

	coTODO("Check memory leaks");
}

coLocalAllocator::~coLocalAllocator()
{
}

void* coLocalAllocator::Allocate(coUint32 _size8)
{
	const coUint32 newStackAllocated = stackAllocated + _size8;
	if (newStackAllocated <= maxStackAlloc)
	{
		void* p = stackBuffer + stackAllocated;
		stackAllocated = newStackAllocated;
		return p;
	}
	else
	{
		coAllocator* defaultAllocator = coAllocator::GetHeap();
		coASSERT(defaultAllocator);
		return defaultAllocator->Allocate(_size8);
	}
}

void* coLocalAllocator::AllocateAligned(coUint32 /*_size8*/, coUint /*_alignment*/)
{
	coWARN_NOT_AVAILABLE();
	return nullptr;
}

void coLocalAllocator::Free(void* _p)
{
	if (_p < stackBuffer || _p >= (stackBuffer + maxStackAlloc))
	{
		coAllocator* defaultAllocator = coAllocator::GetHeap();
		coASSERT(defaultAllocator);
		defaultAllocator->Free(_p);
	}
}

void coLocalAllocator::FreeAligned(void* _p)
{
	if (_p < stackBuffer || _p >= (stackBuffer + maxStackAlloc))
	{
		coAllocator* defaultAllocator = coAllocator::GetHeap();
		coASSERT(defaultAllocator);
		defaultAllocator->FreeAligned(_p);
	}
}
<commit_msg>Fixed comment typo.<commit_after>// Copyright(c) 2016 <NAME>
// Distributed under the MIT License (See accompanying file LICENSE.md file or copy at http://opensource.org/licenses/MIT).
#pragma once
#include "memory/pch.h"
#include "memory/allocator/coLocalAllocator.h"
#include "debug/log/coAssert.h"
#include "debug/log/coLog.h"

coLocalAllocator::coLocalAllocator(coUint32 _maxStackAlloc)
	: stackBuffer(nullptr)
	, stackAllocated(0)
	, maxStackAlloc(_maxStackAlloc)
{
	coASSERT(maxStackAlloc < 16 * 1024); // safety
	stackBuffer = static_cast<coByte*>(::alloca(maxStackAlloc));
	coASSERT(stackBuffer);

	coTODO("Check for memory leaks");
}

coLocalAllocator::~coLocalAllocator()
{
}

void* coLocalAllocator::Allocate(coUint32 _size8)
{
	const coUint32 newStackAllocated = stackAllocated + _size8;
	if (newStackAllocated <= maxStackAlloc)
	{
		void* p = stackBuffer + stackAllocated;
		stackAllocated = newStackAllocated;
		return p;
	}
	else
	{
		coAllocator* defaultAllocator = coAllocator::GetHeap();
		coASSERT(defaultAllocator);
		return defaultAllocator->Allocate(_size8);
	}
}

void* coLocalAllocator::AllocateAligned(coUint32 /*_size8*/, coUint /*_alignment*/)
{
	coWARN_NOT_AVAILABLE();
	return nullptr;
}

void coLocalAllocator::Free(void* _p)
{
	if (_p < stackBuffer || _p >= (stackBuffer + maxStackAlloc))
	{
		coAllocator* defaultAllocator = coAllocator::GetHeap();
		coASSERT(defaultAllocator);
		defaultAllocator->Free(_p);
	}
}

void coLocalAllocator::FreeAligned(void* _p)
{
	if (_p < stackBuffer || _p >= (stackBuffer + maxStackAlloc))
	{
		coAllocator* defaultAllocator = coAllocator::GetHeap();
		coASSERT(defaultAllocator);
		defaultAllocator->FreeAligned(_p);
	}
}

{'fraction_non_alphanumeric': 0.13153206650831353, 'fraction_numerical': 0.013657957244655582, 'mean_word_length': 6.092631578947368, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1071843', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1172, 'n_words': 215}