Blame src/microhttpd/memorypool.h

Packit 875988
/*
Packit 875988
     This file is part of libmicrohttpd
Packit 875988
     Copyright (C) 2007, 2009 Daniel Pittman and Christian Grothoff
Packit 875988
Packit 875988
     This library is free software; you can redistribute it and/or
Packit 875988
     modify it under the terms of the GNU Lesser General Public
Packit 875988
     License as published by the Free Software Foundation; either
Packit 875988
     version 2.1 of the License, or (at your option) any later version.
Packit 875988
Packit 875988
     This library is distributed in the hope that it will be useful,
Packit 875988
     but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 875988
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 875988
     Lesser General Public License for more details.
Packit 875988
Packit 875988
     You should have received a copy of the GNU Lesser General Public
Packit 875988
     License along with this library; if not, write to the Free Software
Packit 875988
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 875988
*/
Packit 875988
Packit 875988
/**
Packit 875988
 * @file memorypool.h
Packit 875988
 * @brief memory pool; mostly used for efficient (de)allocation
Packit 875988
 *        for each connection and bounding memory use for each
Packit 875988
 *        request
Packit 875988
 * @author Christian Grothoff
Packit 875988
 */
Packit 875988
Packit 875988
#ifndef MEMORYPOOL_H
Packit 875988
#define MEMORYPOOL_H
Packit 875988
Packit 875988
#include "internal.h"
Packit 875988
Packit 875988
/**
Packit 875988
 * Opaque handle for a memory pool.
Packit 875988
 * Pools are not reentrant and must not be used
Packit 875988
 * by multiple threads.
Packit 875988
 */
Packit 875988
struct MemoryPool;
Packit 875988
Packit 875988
Packit 875988
/**
Packit 875988
 * Create a memory pool.
Packit 875988
 *
Packit 875988
 * @param max maximum size of the pool
Packit 875988
 * @return NULL on error
Packit 875988
 */
Packit 875988
struct MemoryPool *
Packit 875988
MHD_pool_create (size_t max);
Packit 875988
Packit 875988
Packit 875988
/**
Packit 875988
 * Destroy a memory pool.
Packit 875988
 *
Packit 875988
 * @param pool memory pool to destroy
Packit 875988
 */
Packit 875988
void
Packit 875988
MHD_pool_destroy (struct MemoryPool *pool);
Packit 875988
Packit 875988
Packit 875988
/**
Packit 875988
 * Allocate size bytes from the pool.
Packit 875988
 *
Packit 875988
 * @param pool memory pool to use for the operation
Packit 875988
 * @param size number of bytes to allocate
Packit 875988
 * @param from_end allocate from end of pool (set to #MHD_YES);
Packit 875988
 *        use this for small, persistent allocations that
Packit 875988
 *        will never be reallocated
Packit 875988
 * @return NULL if the pool cannot support size more
Packit 875988
 *         bytes
Packit 875988
 */
Packit 875988
void *
Packit 875988
MHD_pool_allocate (struct MemoryPool *pool,
Packit 875988
		   size_t size,
Packit 875988
                   int from_end);
Packit 875988
Packit 875988
Packit 875988
/**
Packit 875988
 * Reallocate a block of memory obtained from the pool.
Packit 875988
 * This is particularly efficient when growing or
Packit 875988
 * shrinking the block that was last (re)allocated.
Packit 875988
 * If the given block is not the most recently
Packit 875988
 * (re)allocated block, the memory of the previous
Packit 875988
 * allocation may be leaked until the pool is
Packit 875988
 * destroyed (and copying the data maybe required).
Packit 875988
 *
Packit 875988
 * @param pool memory pool to use for the operation
Packit 875988
 * @param old the existing block
Packit 875988
 * @param old_size the size of the existing block
Packit 875988
 * @param new_size the new size of the block
Packit 875988
 * @return new address of the block, or
Packit 875988
 *         NULL if the pool cannot support new_size
Packit 875988
 *         bytes (old continues to be valid for old_size)
Packit 875988
 */
Packit 875988
void *
Packit 875988
MHD_pool_reallocate (struct MemoryPool *pool,
Packit 875988
		     void *old,
Packit 875988
		     size_t old_size,
Packit 875988
		     size_t new_size);
Packit 875988
Packit 875988
Packit 875988
/**
Packit 875988
 * Check how much memory is left in the @a pool
Packit 875988
 *
Packit 875988
 * @param pool pool to check
Packit 875988
 * @return number of bytes still available in @a pool
Packit 875988
 */
Packit 875988
size_t
Packit 875988
MHD_pool_get_free (struct MemoryPool *pool);
Packit 875988
Packit 875988
Packit 875988
/**
Packit 875988
 * Clear all entries from the memory pool except
Packit 875988
 * for @a keep of the given @a copy_bytes.  The pointer
Packit 875988
 * returned should be a buffer of @a new_size where
Packit 875988
 * the first @a copy_bytes are from @a keep.
Packit 875988
 *
Packit 875988
 * @param pool memory pool to use for the operation
Packit 875988
 * @param keep pointer to the entry to keep (maybe NULL)
Packit 875988
 * @param copy_bytes how many bytes need to be kept at this address
Packit 875988
 * @param new_size how many bytes should the allocation we return have?
Packit 875988
 *                 (should be larger or equal to @a copy_bytes)
Packit 875988
 * @return addr new address of @a keep (if it had to change)
Packit 875988
 */
Packit 875988
void *
Packit 875988
MHD_pool_reset (struct MemoryPool *pool,
Packit 875988
		void *keep,
Packit 875988
		size_t copy_bytes,
Packit 875988
                size_t new_size);
Packit 875988
Packit 875988
#endif