Macros | Functions | Variables
z-quark.c File Reference

Save memory by storing strings in a global array, ensuring that each is only allocated once. More...

#include "z-virt.h"
#include "z-quark.h"
#include "init.h"


#define QUARKS_INIT   16


quark_t quark_add (const char *str)
 Return a quark for the string 'str'. More...
const char * quark_str (quark_t q)
 Return the string corresponding to the quark. More...
void quarks_init (void)
 Initialise the quarks package. More...
void quarks_free (void)
 De-initialise the quarks package. More...


static char ** quarks
static size_t nr_quarks = 1
static size_t alloc_quarks = 0
struct init_module z_quark_module

Detailed Description

Save memory by storing strings in a global array, ensuring that each is only allocated once.

Copyright (c) 1997 Ben Harrison Copyright (c) 2007 "Elly"

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation


#define QUARKS_INIT   16

Referenced by quarks_init().

Function Documentation

◆ quark_add()

quark_t quark_add ( const char *  str)

◆ quark_str()

const char* quark_str ( quark_t  q)

◆ quarks_free()

void quarks_free ( void  )

De-initialise the quarks package.

References i, mem_free(), nr_quarks, quarks, and string_free().

Referenced by teardown_tests().

◆ quarks_init()

void quarks_init ( void  )

Initialise the quarks package.

References alloc_quarks, mem_zalloc(), nr_quarks, quarks, and QUARKS_INIT.

Referenced by setup_tests().

Variable Documentation

◆ alloc_quarks

size_t alloc_quarks = 0

Referenced by quark_add(), and quarks_init().

◆ nr_quarks

size_t nr_quarks = 1

◆ quarks

char** quarks

◆ z_quark_module

struct init_module z_quark_module
Initial value:
= {
.name = "z-quark",
.init = quarks_init,
.cleanup = quarks_free
void quarks_init(void)
Initialise the quarks package.
Definition: z-quark.c:55
void quarks_free(void)
De-initialise the quarks package.
Definition: z-quark.c:62