Replaces individual malloc/free string management with a contiguous pool
(default 32KB) and compacting GC, matching the original GW-BASIC's
GETSPA/GARBAG architecture. Allocation is a bump pointer; gw_str_free()
is a no-op (descriptors are nulled, data reclaimed by GC). Compaction
runs at statement boundaries when the pool drops below 4KB free, walking
the variable table and array storage to relocate live strings.
FRE() now returns actual free pool space. FRE("") triggers a GC pass
before reporting. CLEAR n sets the string space size.
19 lines
683 B
C
19 lines
683 B
C
#ifndef STRPOOL_H
|
|
#define STRPOOL_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#define STRPOOL_DEFAULT_SIZE (32 * 1024) /* 32KB — generous vs original's ~3KB */
|
|
#define STRPOOL_GC_THRESHOLD 4096 /* GC when less than 4KB free */
|
|
|
|
void strpool_init(size_t size);
|
|
void strpool_shutdown(void);
|
|
void strpool_reset(size_t size); /* resize and clear (0 = keep current size) */
|
|
char *strpool_alloc(int len); /* bump-allocate from pool */
|
|
void strpool_gc(void); /* compact: walk vars+arrays, squeeze out dead space */
|
|
size_t strpool_free(void); /* bytes available */
|
|
bool strpool_owns(const char *p); /* true if p points into the pool */
|
|
|
|
#endif
|