Angband
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"

Macros

#define QUARKS_INIT   16

Functions

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

Variables

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_t quark_add ( const char *  str)
const char* quark_str ( quark_t  q)
void quarks_free ( void  )

De-initialise the quarks package.

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

Referenced by teardown_tests().

void quarks_init ( void  )

Initialise the quarks package.

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

Referenced by setup_tests().

Variable Documentation

size_t alloc_quarks = 0
static

Referenced by quark_add(), and quarks_init().

size_t nr_quarks = 1
static

Referenced by quark_add(), quark_str(), and quarks_free().

char** quarks
static
struct init_module z_quark_module
Initial value:
{
.name = "z-quark",
.init = quarks_init,
.cleanup = quarks_free
}