Blame include/apr_rmm.h

Packit 383869
/* Licensed to the Apache Software Foundation (ASF) under one or more
Packit 383869
 * contributor license agreements.  See the NOTICE file distributed with
Packit 383869
 * this work for additional information regarding copyright ownership.
Packit 383869
 * The ASF licenses this file to You under the Apache License, Version 2.0
Packit 383869
 * (the "License"); you may not use this file except in compliance with
Packit 383869
 * the License.  You may obtain a copy of the License at
Packit 383869
 *
Packit 383869
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 383869
 *
Packit 383869
 * Unless required by applicable law or agreed to in writing, software
Packit 383869
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 383869
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 383869
 * See the License for the specific language governing permissions and
Packit 383869
 * limitations under the License.
Packit 383869
 */
Packit 383869
Packit 383869
#ifndef APR_RMM_H
Packit 383869
#define APR_RMM_H
Packit 383869
/** 
Packit 383869
 * @file apr_rmm.h
Packit 383869
 * @brief APR-UTIL Relocatable Memory Management Routines
Packit 383869
 */
Packit 383869
/**
Packit 383869
 * @defgroup APR_Util_RMM Relocatable Memory Management Routines
Packit 383869
 * @ingroup APR_Util
Packit 383869
 * @{
Packit 383869
 */
Packit 383869
Packit 383869
#include "apr.h"
Packit 383869
#include "apr_pools.h"
Packit 383869
#include "apr_errno.h"
Packit 383869
#include "apu.h"
Packit 383869
#include "apr_anylock.h"
Packit 383869
Packit 383869
#ifdef __cplusplus
Packit 383869
extern "C" {
Packit 383869
#endif /* __cplusplus */
Packit 383869
Packit 383869
/** Structure to access Relocatable, Managed Memory */
Packit 383869
typedef struct apr_rmm_t apr_rmm_t;
Packit 383869
Packit 383869
/** Fundamental allocation unit, within a specific apr_rmm_t */
Packit 383869
typedef apr_size_t   apr_rmm_off_t;
Packit 383869
Packit 383869
/**
Packit 383869
 * Initialize a relocatable memory block to be managed by the apr_rmm API.
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param lock An apr_anylock_t of the appropriate type of lock, or NULL
Packit 383869
 *             if no locking is required.
Packit 383869
 * @param membuf The block of relocatable memory to be managed
Packit 383869
 * @param memsize The size of relocatable memory block to be managed
Packit 383869
 * @param cont The pool to use for local storage and management
Packit 383869
 * @remark Both @param membuf and @param memsize must be aligned
Packit 383869
 * (for instance using APR_ALIGN_DEFAULT).
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_rmm_init(apr_rmm_t **rmm, apr_anylock_t *lock,
Packit 383869
                                       void *membuf, apr_size_t memsize, 
Packit 383869
                                       apr_pool_t *cont);
Packit 383869
Packit 383869
/**
Packit 383869
 * Destroy a managed memory block.
Packit 383869
 * @param rmm The relocatable memory block to destroy
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_rmm_destroy(apr_rmm_t *rmm);
Packit 383869
Packit 383869
/**
Packit 383869
 * Attach to a relocatable memory block already managed by the apr_rmm API.
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param lock An apr_anylock_t of the appropriate type of lock
Packit 383869
 * @param membuf The block of relocatable memory already under management
Packit 383869
 * @param cont The pool to use for local storage and management
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_rmm_attach(apr_rmm_t **rmm, apr_anylock_t *lock,
Packit 383869
                                         void *membuf, apr_pool_t *cont);
Packit 383869
Packit 383869
/**
Packit 383869
 * Detach from the managed block of memory.
Packit 383869
 * @param rmm The relocatable memory block to detach from
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_rmm_detach(apr_rmm_t *rmm);
Packit 383869
Packit 383869
/**
Packit 383869
 * Allocate memory from the block of relocatable memory.
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param reqsize How much memory to allocate
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_rmm_off_t) apr_rmm_malloc(apr_rmm_t *rmm, apr_size_t reqsize);
Packit 383869
Packit 383869
/**
Packit 383869
 * Realloc memory from the block of relocatable memory.
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param entity The memory allocation to realloc
Packit 383869
 * @param reqsize The new size
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_rmm_off_t) apr_rmm_realloc(apr_rmm_t *rmm, void *entity, apr_size_t reqsize);
Packit 383869
Packit 383869
/**
Packit 383869
 * Allocate memory from the block of relocatable memory and initialize it to zero.
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param reqsize How much memory to allocate
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_rmm_off_t) apr_rmm_calloc(apr_rmm_t *rmm, apr_size_t reqsize);
Packit 383869
Packit 383869
/**
Packit 383869
 * Free allocation returned by apr_rmm_malloc or apr_rmm_calloc.
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param entity The memory allocation to free
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_status_t) apr_rmm_free(apr_rmm_t *rmm, apr_rmm_off_t entity);
Packit 383869
Packit 383869
/**
Packit 383869
 * Retrieve the physical address of a relocatable allocation of memory
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param entity The memory allocation to free
Packit 383869
 * @return address The address, aligned with APR_ALIGN_DEFAULT.
Packit 383869
 */
Packit 383869
APU_DECLARE(void *) apr_rmm_addr_get(apr_rmm_t *rmm, apr_rmm_off_t entity);
Packit 383869
Packit 383869
/**
Packit 383869
 * Compute the offset of a relocatable allocation of memory
Packit 383869
 * @param rmm The relocatable memory block
Packit 383869
 * @param entity The physical address to convert to an offset
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_rmm_off_t) apr_rmm_offset_get(apr_rmm_t *rmm, void *entity);
Packit 383869
Packit 383869
/**
Packit 383869
 * Compute the required overallocation of memory needed to fit n allocs
Packit 383869
 * @param n The number of alloc/calloc regions desired
Packit 383869
 */
Packit 383869
APU_DECLARE(apr_size_t) apr_rmm_overhead_get(int n);
Packit 383869
Packit 383869
#ifdef __cplusplus
Packit 383869
}
Packit 383869
#endif
Packit 383869
/** @} */
Packit 383869
#endif  /* ! APR_RMM_H */
Packit 383869