1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
21
* @brief APR-UTIL Relocatable Memory Management Routines
24
* @defgroup APR_Util_RMM Relocatable Memory Management Routines
30
#include "apr_pools.h"
31
#include "apr_errno.h"
33
#include "apr_anylock.h"
37
#endif /* __cplusplus */
39
/** Structure to access Relocatable, Managed Memory */
40
typedef struct apr_rmm_t apr_rmm_t;
42
/** Fundamental allocation unit, within a specific apr_rmm_t */
43
typedef apr_size_t apr_rmm_off_t;
46
* Initialize a relocatable memory block to be managed by the apr_rmm API.
47
* @param rmm The relocatable memory block
48
* @param lock An apr_anylock_t of the appropriate type of lock, or NULL
49
* if no locking is required.
50
* @param membuf The block of relocatable memory to be managed
51
* @param memsize The size of relocatable memory block to be managed
52
* @param cont The pool to use for local storage and management
53
* @remark Both @param membuf and @param memsize must be aligned
54
* (for instance using APR_ALIGN_DEFAULT).
56
APU_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, apr_anylock_t *lock,
57
void *membuf, apr_size_t memsize,
61
* Destroy a managed memory block.
62
* @param rmm The relocatable memory block to destroy
64
APU_DECLARE(apr_status_t) apr_rmm_destroy(apr_rmm_t *rmm);
67
* Attach to a relocatable memory block already managed by the apr_rmm API.
68
* @param rmm The relocatable memory block
69
* @param lock An apr_anylock_t of the appropriate type of lock
70
* @param membuf The block of relocatable memory already under management
71
* @param cont The pool to use for local storage and management
73
APU_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, apr_anylock_t *lock,
74
void *membuf, apr_pool_t *cont);
77
* Detach from the managed block of memory.
78
* @param rmm The relocatable memory block to detach from
80
APU_DECLARE(apr_status_t) apr_rmm_detach(apr_rmm_t *rmm);
83
* Allocate memory from the block of relocatable memory.
84
* @param rmm The relocatable memory block
85
* @param reqsize How much memory to allocate
87
APU_DECLARE(apr_rmm_off_t) apr_rmm_malloc(apr_rmm_t *rmm, apr_size_t reqsize);
90
* Realloc memory from the block of relocatable memory.
91
* @param rmm The relocatable memory block
92
* @param entity The memory allocation to realloc
93
* @param reqsize The new size
95
APU_DECLARE(apr_rmm_off_t) apr_rmm_realloc(apr_rmm_t *rmm, void *entity, apr_size_t reqsize);
98
* Allocate memory from the block of relocatable memory and initialize it to zero.
99
* @param rmm The relocatable memory block
100
* @param reqsize How much memory to allocate
102
APU_DECLARE(apr_rmm_off_t) apr_rmm_calloc(apr_rmm_t *rmm, apr_size_t reqsize);
105
* Free allocation returned by apr_rmm_malloc or apr_rmm_calloc.
106
* @param rmm The relocatable memory block
107
* @param entity The memory allocation to free
109
APU_DECLARE(apr_status_t) apr_rmm_free(apr_rmm_t *rmm, apr_rmm_off_t entity);
112
* Retrieve the physical address of a relocatable allocation of memory
113
* @param rmm The relocatable memory block
114
* @param entity The memory allocation to free
115
* @return address The address, aligned with APR_ALIGN_DEFAULT.
117
APU_DECLARE(void *) apr_rmm_addr_get(apr_rmm_t *rmm, apr_rmm_off_t entity);
120
* Compute the offset of a relocatable allocation of memory
121
* @param rmm The relocatable memory block
122
* @param entity The physical address to convert to an offset
124
APU_DECLARE(apr_rmm_off_t) apr_rmm_offset_get(apr_rmm_t *rmm, void *entity);
127
* Compute the required overallocation of memory needed to fit n allocs
128
* @param n The number of alloc/calloc regions desired
130
APU_DECLARE(apr_size_t) apr_rmm_overhead_get(int n);
136
#endif /* ! APR_RMM_H */