buffer now stores the number of allocations for debug

This commit is contained in:
Luna 2025-07-06 05:19:44 +02:00
parent ff45377ffe
commit 35c95790ed
2 changed files with 4 additions and 2 deletions

View file

@ -1,11 +1,12 @@
#include "buffer.h" #include "buffer.h"
void buffer::write(char *data_in, int data_size) void buffer::write(char *data_in, size_t data_size)
{ {
if (data_size > allocated - size) if (data_size > allocated - size)
{ {
allocated += (size + data_size) + BUFFER_SIZE; allocated += (size + data_size) + BUFFER_SIZE;
data = (char *)realloc(data, allocated); data = (char *)realloc(data, allocated);
allocations++;
if (!data) if (!data)
{ {
throw std::runtime_error("Allocation failed"); throw std::runtime_error("Allocation failed");

View file

@ -9,8 +9,9 @@ struct buffer
char *data; char *data;
size_t size; size_t size;
size_t allocated; size_t allocated;
int allocations;
void write(char *data_in, int data_size); void write(char *data_in, size_t data_size);
void remove(int offset, int remove_size); void remove(int offset, int remove_size);
~buffer() ~buffer()