00001 /* -*- coding:utf-8 -*- 00002 Copyright (c) 2009, Fixstars Corporation 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, 00006 are permitted provided that the following conditions are met: 00007 00008 * Redistributions of source code must retain the above copyright notice, 00009 this list of conditions and the following disclaimer. 00010 00011 * Redistributions in binary form must reproduce the above copyright notice, 00012 this list of conditions and the following disclaimer in the documentation 00013 and/or other materials provided with the distribution. 00014 00015 * Neither the name of Fixstars Corporation nor the names of its contributors 00016 may be used to endorse or promote products derived from this software 00017 without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00020 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 00023 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00026 AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00028 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00037 #ifndef CTRUMP_MEMPOOL_H 00038 #define CTRUMP_MEMPOOL_H 00039 00040 #include "ctrump/common/dll.h" 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00049 struct ctrump_mempool { 00050 unsigned int entry_num; 00051 unsigned int entry_index; 00052 unsigned int entry_byte_size; 00053 unsigned int entry_byte_remain; 00054 unsigned int entry_byte_pos; 00055 unsigned char **data_entry; 00056 }; 00057 00061 CTRUMP_EXTDEF extern void ctrump_mempool_init(struct ctrump_mempool *p, 00062 unsigned int size_hint); 00063 00067 CTRUMP_EXTDEF extern void ctrump_mempool_destroy(struct ctrump_mempool *p); 00068 00078 CTRUMP_EXTDEF extern void *ctrump_mempool_alloc_align(struct ctrump_mempool *p, 00079 unsigned int align_shift, 00080 unsigned int size); 00081 00089 #define ctrump_mempool_alloc(p,s) ctrump_mempool_alloc_align(p, 3, s) 00090 00091 CTRUMP_EXTDEF extern char *ctrump_mempool_strdup(struct ctrump_mempool *p, 00092 char *str); 00093 00094 #ifdef __cplusplus 00095 } 00096 #endif 00097 00098 #endif