dev/c/realloc_speed_test/smart_string.c

36 lines
555 B
C

#include "smart_string.h"
#include <stdlib.h>
#include "xmalloc.h"
void smart_string_init(struct smart_string_s *ss)
{
ss->string_ptr = NULL;
ss->allocated = 0;
ss->length = 0;
}
void smart_string_resize(struct smart_string_s *ss, size_t size)
{
size_t n = size << 1;
size_t saved_size = size;
size_t count = 1;
while (size) {
size >>= 1;
count ++;
}
size_t n = 1LU << count;
xrealloc(&ss->string_ptr, saved_size);
}
void smart_string_free(struct smart_string_s *ss)
{
xfree(&ss->string_ptr);
ss->allocated = 0;
ss->length = 0;
}