2 * fribidi-mem.c - memory manipulation routines
4 * $Id: fribidi-mem.c,v 1.8 2006-01-31 03:23:13 behdad Exp $
6 * $Date: 2006-01-31 03:23:13 $
8 * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-mem.c,v $
11 * Behdad Esfahbod, 2001, 2002, 2004
13 * Copyright (C) 2004 Sharif FarsiWeb, Inc
14 * Copyright (C) 2001,2002 Behdad Esfahbod
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with this library, in a file named COPYING; if not, write to the
28 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 * Boston, MA 02110-1301, USA
31 * For licensing issues, contact <license@farsiweb.info>.
38 #if FRIBIDI_USE_GLIB+0
40 #if USE_SIMPLE_MALLOC+0
43 struct _FriBidiMemChunk
52 fribidi_mem_chunk_new (
56 unsigned long area_size,
60 register FriBidiMemChunk *m;
62 fribidi_assert (area_size >= atom_size * 8);
64 m = (FriBidiMemChunk *) fribidi_malloc (sizeof (FriBidiMemChunk));
68 m->atom_size = atom_size;
69 m->area_size = area_size;
78 fribidi_mem_chunk_alloc (
80 FriBidiMemChunk *mem_chunk
83 fribidi_assert (mem_chunk);
86 (mem_chunk->empty_size < mem_chunk->atom_size)
88 register void *chunk = fribidi_malloc (mem_chunk->area_size);
94 (char *) mem_chunk->chunk + mem_chunk->empty_size -
96 chunk = (char *) chunk + mem_chunk->atom_size;
97 mem_chunk->chunk = chunk;
98 mem_chunk->empty_size = mem_chunk->area_size - mem_chunk->atom_size;
105 register void *m = mem_chunk->chunk;
106 mem_chunk->chunk = (char *) mem_chunk->chunk + mem_chunk->atom_size;
107 mem_chunk->empty_size -= mem_chunk->atom_size;
114 fribidi_mem_chunk_destroy (
116 FriBidiMemChunk *mem_chunk
119 register void *chunk;
121 fribidi_assert (mem_chunk);
124 (char *) mem_chunk->chunk + mem_chunk->empty_size - mem_chunk->area_size;
128 register void *tofree = chunk;
129 chunk = *(void **) chunk;
130 fribidi_free (tofree);
132 fribidi_free (mem_chunk);
135 #endif /* !USE_SIMPLE_MALLOC */
136 #endif /* !FRIBIDI_USE_GLIB */
138 /* Editor directions:
139 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent