Add temp allocator scribble. Make bufferstream safer.

This commit is contained in:
Christoffer Lerno
2024-08-11 01:17:03 +02:00
parent 224c3f4123
commit 2706495668
3 changed files with 16 additions and 12 deletions

View File

@@ -65,6 +65,16 @@ fn void TempAllocator.release(&self, void* old_pointer, bool) @dynamic
fn void TempAllocator.reset(&self, usz mark) @dynamic
{
TempAllocatorPage *last_page = self.last_page;
$if env::COMPILER_SAFE_MODE:
if (!last_page)
{
usz cleaned = self.used - mark;
if (cleaned > 0)
{
self.data[mark : cleaned] = 0xAA;
}
}
$endif
while (last_page && last_page.mark > mark)
{
TempAllocatorPage *to_free = last_page;

View File

@@ -141,15 +141,9 @@ fn usz! copy_to(InStream in, OutStream dst, char[] buffer = {})
if (&dst.read_to) return dst.read_to(in);
$switch (env::MEMORY_ENV)
$case NORMAL:
@pool()
{
return copy_through_buffer(in, dst, mem::temp_alloc_array(char, 4096));
};
return copy_through_buffer(in, dst, &&char[4096]{});
$case SMALL:
@pool()
{
return copy_through_buffer(in, dst, mem::temp_alloc_array(char, 1024));
};
return copy_through_buffer(in, dst, &&char[1024]{});
$case TINY:
$case NONE:
return copy_through_buffer(in, dst, &&(char[256]{}));