BRL-CAD
mem.h
Go to the documentation of this file.
1/* M E M . H
2 * BRL-CAD
3 *
4 * Copyright (c) 1993-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @file rt/mem.h
21 *
22 */
23
24#ifndef RT_MEM_H
25#define RT_MEM_H
26
27#include "common.h"
28#include "vmath.h"
29#include "rt/defines.h"
30
31__BEGIN_DECLS
32
33/**
34 * These structures are used to manage internal resource maps.
35 * Typically these maps describe some kind of memory or file space.
36 */
37struct mem_map {
38 struct mem_map *m_nxtp; /**< @brief Linking pointer to next element */
39 size_t m_size; /**< @brief Size of this free element */
40 b_off_t m_addr; /**< @brief Address of start of this element */
41};
42#define MAP_NULL ((struct mem_map *) 0)
43
44/* memalloc.c -- non PARALLEL routines */
45
46/**
47 * Takes: & pointer of map,
48 * size.
49 *
50 * Returns: NULL Error
51 * address Otherwise
52 *
53 * Comments:
54 * Algorithm is first fit.
55 */
56RT_EXPORT extern size_t rt_memalloc(struct mem_map **pp,
57 size_t size);
58
59/**
60 * Takes: & pointer of map,
61 * size.
62 *
63 * Returns: NULL Error
64 * address Otherwise
65 *
66 * Comments:
67 * Algorithm is BEST fit.
68 */
69RT_EXPORT extern struct mem_map * rt_memalloc_nosplit(struct mem_map **pp,
70 size_t size);
71
72/**
73 * Takes:
74 * size,
75 * address.
76 *
77 * Comments:
78 * The routine does not check for wrap around when increasing sizes
79 * or changing addresses. Other wrap-around conditions are flagged.
80 */
81RT_EXPORT extern void rt_memfree(struct mem_map **pp,
82 size_t size,
83 b_off_t addr);
84
85/**
86 * Take everything on the current memory chain, and place it on the
87 * freelist.
88 */
89RT_EXPORT extern void rt_mempurge(struct mem_map **pp);
90
91/**
92 * Return all the storage used by the rt_mem_freemap.
93 */
94RT_EXPORT extern void rt_memclose(void);
95
96
97__END_DECLS
98
99#endif /* RT_MEM_H */
100
101/*
102 * Local Variables:
103 * tab-width: 8
104 * mode: C
105 * indent-tabs-mode: t
106 * c-file-style: "stroustrup"
107 * End:
108 * ex: shiftwidth=4 tabstop=8
109 */
Header file for the BRL-CAD common definitions.
void float float int int int int float * size
Definition: tig.h:132
#define b_off_t
Definition: common.h:222
void rt_memclose(void)
struct mem_map * rt_memalloc_nosplit(struct mem_map **pp, size_t size)
size_t rt_memalloc(struct mem_map **pp, size_t size)
void rt_memfree(struct mem_map **pp, size_t size, b_off_t addr)
void rt_mempurge(struct mem_map **pp)
Definition: mem.h:37
size_t m_size
Size of this free element.
Definition: mem.h:39
b_off_t m_addr
Address of start of this element.
Definition: mem.h:40
struct mem_map * m_nxtp
Linking pointer to next element.
Definition: mem.h:38
fundamental vector, matrix, quaternion math macros