This commit is contained in:
Dante
2026-05-22 11:54:15 -07:00
parent 05f197c291
commit b47ea35fe4
935 changed files with 1016163 additions and 1 deletions

View File

@ -0,0 +1,53 @@
#ifndef HX_STRING_ALLOC
#define HX_STRING_ALLOC
#include <stdlib.h>
#include <stdint.h>
namespace hx
{
class IStringAlloc
{
public:
virtual void *allocBytes(size_t inBytes) = 0;
protected:
~IStringAlloc(){};
};
template<int STACK>
class StringAlloc : public IStringAlloc
{
char buffer[STACK];
size_t alloced;
char *heap;
public:
inline StringAlloc() : alloced(0), heap(0) { }
~StringAlloc()
{
if (heap)
free(heap);
}
void *allocBytes(size_t inBytes)
{
if (inBytes<=STACK)
return buffer;
if (inBytes>alloced)
{
alloced = inBytes;
heap = (char *)realloc(heap, alloced);
}
return heap;
}
private:
StringAlloc(const StringAlloc &);
void operator=(const StringAlloc &);
};
typedef StringAlloc<100> strbuf;
} // end namespace hx
#endif