File: string_alloc.h

package info (click to toggle)
staden 2.0.0%2Bb11-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 21,556 kB
  • sloc: ansic: 240,603; tcl: 65,360; cpp: 12,854; makefile: 11,201; sh: 2,952; fortran: 2,033; perl: 63; awk: 46
file content (27 lines) | stat: -rw-r--r-- 598 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef _STRING_ALLOC_H_
#define _STRING_ALLOC_H_

/* 
   A pooled string allocator intended to cut down on the
   memory overhead of many small string allocations.
   
   Andrew Whitwham, September 2010.
*/

typedef struct {
    char *str;
    size_t used;
} string_t;

typedef struct {
    size_t max_length;
    size_t nstrings;
    string_t *strings;
} string_alloc_t;

string_alloc_t *string_pool_create(size_t max_length);
void string_pool_destroy(string_alloc_t *a_str);
char *string_alloc(string_alloc_t *a_str, size_t length);
char *string_dup(string_alloc_t *a_str, char *instr);

#endif