Apache Portable Runtime
apr_rmm.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef APR_RMM_H
00018 #define APR_RMM_H
00019 /** 
00020  * @file apr_rmm.h
00021  * @brief APR-UTIL Relocatable Memory Management Routines
00022  */
00023 /**
00024  * @defgroup APR_Util_RMM Relocatable Memory Management Routines
00025  * @ingroup APR
00026  * @{
00027  */
00028 
00029 #include "apr.h"
00030 #include "apr_pools.h"
00031 #include "apr_errno.h"
00032 #include "apu.h"
00033 #include "apr_anylock.h"
00034 
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif /* __cplusplus */
00038 
00039 /** Structure to access Relocatable, Managed Memory */
00040 typedef struct apr_rmm_t apr_rmm_t;
00041 
00042 /** Fundamental allocation unit, within a specific apr_rmm_t */
00043 typedef apr_size_t   apr_rmm_off_t;
00044 
00045 /**
00046  * Initialize a relocatable memory block to be managed by the apr_rmm API.
00047  * @param rmm The relocatable memory block
00048  * @param lock An apr_anylock_t of the appropriate type of lock, or NULL
00049  *             if no locking is required.
00050  * @param membuf The block of relocatable memory to be managed
00051  * @param memsize The size of relocatable memory block to be managed
00052  * @param cont The pool to use for local storage and management
00053  * @remark Both @param membuf and @param memsize must be aligned
00054  * (for instance using APR_ALIGN_DEFAULT).
00055  */
00056 APR_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, apr_anylock_t *lock,
00057                                        void *membuf, apr_size_t memsize, 
00058                                        apr_pool_t *cont);
00059 
00060 /**
00061  * Destroy a managed memory block.
00062  * @param rmm The relocatable memory block to destroy
00063  */
00064 APR_DECLARE(apr_status_t) apr_rmm_destroy(apr_rmm_t *rmm);
00065 
00066 /**
00067  * Attach to a relocatable memory block already managed by the apr_rmm API.
00068  * @param rmm The relocatable memory block
00069  * @param lock An apr_anylock_t of the appropriate type of lock
00070  * @param membuf The block of relocatable memory already under management
00071  * @param cont The pool to use for local storage and management
00072  */
00073 APR_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, apr_anylock_t *lock,
00074                                          void *membuf, apr_pool_t *cont);
00075 
00076 /**
00077  * Detach from the managed block of memory.
00078  * @param rmm The relocatable memory block to detach from
00079  */
00080 APR_DECLARE(apr_status_t) apr_rmm_detach(apr_rmm_t *rmm);
00081 
00082 /**
00083  * Allocate memory from the block of relocatable memory.
00084  * @param rmm The relocatable memory block
00085  * @param reqsize How much memory to allocate
00086  */
00087 APR_DECLARE(apr_rmm_off_t) apr_rmm_malloc(apr_rmm_t *rmm, apr_size_t reqsize);
00088 
00089 /**
00090  * Realloc memory from the block of relocatable memory.
00091  * @param rmm The relocatable memory block
00092  * @param entity The memory allocation to realloc
00093  * @param reqsize The new size
00094  */
00095 APR_DECLARE(apr_rmm_off_t) apr_rmm_realloc(apr_rmm_t *rmm, void *entity, apr_size_t reqsize);
00096 
00097 /**
00098  * Allocate memory from the block of relocatable memory and initialize it to zero.
00099  * @param rmm The relocatable memory block
00100  * @param reqsize How much memory to allocate
00101  */
00102 APR_DECLARE(apr_rmm_off_t) apr_rmm_calloc(apr_rmm_t *rmm, apr_size_t reqsize);
00103 
00104 /**
00105  * Free allocation returned by apr_rmm_malloc or apr_rmm_calloc.
00106  * @param rmm The relocatable memory block
00107  * @param entity The memory allocation to free
00108  */
00109 APR_DECLARE(apr_status_t) apr_rmm_free(apr_rmm_t *rmm, apr_rmm_off_t entity);
00110 
00111 /**
00112  * Retrieve the physical address of a relocatable allocation of memory
00113  * @param rmm The relocatable memory block
00114  * @param entity The memory allocation to free
00115  * @return address The address, aligned with APR_ALIGN_DEFAULT.
00116  */
00117 APR_DECLARE(void *) apr_rmm_addr_get(apr_rmm_t *rmm, apr_rmm_off_t entity);
00118 
00119 /**
00120  * Compute the offset of a relocatable allocation of memory
00121  * @param rmm The relocatable memory block
00122  * @param entity The physical address to convert to an offset
00123  */
00124 APR_DECLARE(apr_rmm_off_t) apr_rmm_offset_get(apr_rmm_t *rmm, void *entity);
00125 
00126 /**
00127  * Compute the required overallocation of memory needed to fit n allocs
00128  * @param n The number of alloc/calloc regions desired
00129  */
00130 APR_DECLARE(apr_size_t) apr_rmm_overhead_get(int n);
00131 
00132 #ifdef __cplusplus
00133 }
00134 #endif
00135 /** @} */
00136 #endif  /* ! APR_RMM_H */
00137 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines