Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:09

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/container for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 #ifndef BOOST_CONTAINER_ALLOC_LIB_EXT_H
0011 #define BOOST_CONTAINER_ALLOC_LIB_EXT_H
0012 
0013 #include <stddef.h>
0014 
0015 #ifdef _MSC_VER
0016 #pragma warning (push)
0017 #pragma warning (disable : 4127)
0018 #endif
0019 
0020 #ifdef __cplusplus
0021 extern "C" {
0022 #endif
0023 
0024 /*!An forward iterator to traverse the elements of a memory chain container.*/
0025 typedef struct multialloc_node_impl
0026 {
0027    struct multialloc_node_impl *next_node_ptr;
0028 } boost_cont_memchain_node;
0029 
0030 
0031 /*!An forward iterator to traverse the elements of a memory chain container.*/
0032 typedef struct multialloc_it_impl
0033 {
0034    boost_cont_memchain_node *node_ptr;
0035 } boost_cont_memchain_it;
0036 
0037 /*!Memory chain: A container holding memory portions allocated by boost_cont_multialloc_nodes
0038    and boost_cont_multialloc_arrays functions.*/
0039 typedef struct boost_cont_memchain_impl
0040 {
0041    size_t                   num_mem;
0042    boost_cont_memchain_node  root_node;
0043    boost_cont_memchain_node *last_node_ptr;
0044 } boost_cont_memchain;
0045 
0046 /*!Advances the iterator one position so that it points to the next element in the memory chain*/
0047 #define BOOST_CONTAINER_MEMIT_NEXT(IT)         (IT.node_ptr = IT.node_ptr->next_node_ptr)
0048 
0049 /*!Returns the address of the memory chain currently pointed by the iterator*/
0050 #define BOOST_CONTAINER_MEMIT_ADDR(IT)      ((void*)IT.node_ptr)
0051 
0052 /*!Initializer for an iterator pointing to the position before the first element*/
0053 #define BOOST_CONTAINER_MEMCHAIN_BEFORE_BEGIN_IT(PMEMCHAIN)   { &((PMEMCHAIN)->root_node) }
0054 
0055 /*!Initializer for an iterator pointing to the first element*/
0056 #define BOOST_CONTAINER_MEMCHAIN_BEGIN_IT(PMEMCHAIN)   {(PMEMCHAIN)->root_node.next_node_ptr }
0057 
0058 /*!Initializer for an iterator pointing to the last element*/
0059 #define BOOST_CONTAINER_MEMCHAIN_LAST_IT(PMEMCHAIN)    {(PMEMCHAIN)->last_node_ptr }
0060 
0061 /*!Initializer for an iterator pointing to one past the last element (end iterator)*/
0062 #define BOOST_CONTAINER_MEMCHAIN_END_IT(PMEMCHAIN)     {(boost_cont_memchain_node *)0 }
0063 
0064 /*!True if IT is the end iterator, false otherwise*/
0065 #define BOOST_CONTAINER_MEMCHAIN_IS_END_IT(PMEMCHAIN, IT) (!(IT).node_ptr)
0066 
0067 /*!The address of the first memory portion hold by the memory chain*/
0068 #define BOOST_CONTAINER_MEMCHAIN_FIRSTMEM(PMEMCHAIN)((void*)((PMEMCHAIN)->root_node.next_node_ptr))
0069 
0070 /*!The address of the last memory portion hold by the memory chain*/
0071 #define BOOST_CONTAINER_MEMCHAIN_LASTMEM(PMEMCHAIN) ((void*)((PMEMCHAIN)->last_node_ptr))
0072 
0073 /*!The number of memory portions hold by the memory chain*/
0074 #define BOOST_CONTAINER_MEMCHAIN_SIZE(PMEMCHAIN) ((PMEMCHAIN)->num_mem)
0075 
0076 /*!Initializes the memory chain from the first memory portion, the last memory
0077    portion and number of portions obtained from another memory chain*/
0078 #define BOOST_CONTAINER_MEMCHAIN_INIT_FROM(PMEMCHAIN, FIRST, LAST, NUM)\
0079    (PMEMCHAIN)->last_node_ptr = (boost_cont_memchain_node *)(LAST), \
0080    (PMEMCHAIN)->root_node.next_node_ptr  = (boost_cont_memchain_node *)(FIRST), \
0081    (PMEMCHAIN)->num_mem  = (NUM);\
0082 /**/
0083 
0084 /*!Default initializes a memory chain. Postconditions: begin iterator is end iterator,
0085    the number of portions is zero.*/
0086 #define BOOST_CONTAINER_MEMCHAIN_INIT(PMEMCHAIN)\
0087    ((PMEMCHAIN)->root_node.next_node_ptr = 0, (PMEMCHAIN)->last_node_ptr = &((PMEMCHAIN)->root_node), (PMEMCHAIN)->num_mem = 0)\
0088 /**/
0089 
0090 /*!True if the memory chain is empty (holds no memory portions*/
0091 #define BOOST_CONTAINER_MEMCHAIN_EMPTY(PMEMCHAIN)\
0092    ((PMEMCHAIN)->num_mem == 0)\
0093 /**/
0094 
0095 /*!Inserts a new memory portions in the front of the chain*/
0096 #define BOOST_CONTAINER_MEMCHAIN_PUSH_BACK(PMEMCHAIN, MEM)\
0097    do{\
0098       boost_cont_memchain *____chain____ = (PMEMCHAIN);\
0099       boost_cont_memchain_node *____tmp_mem____ = (boost_cont_memchain_node *)(MEM);\
0100       ____chain____->last_node_ptr->next_node_ptr = ____tmp_mem____;\
0101       ____tmp_mem____->next_node_ptr = 0;\
0102       ____chain____->last_node_ptr = ____tmp_mem____;\
0103       ++____chain____->num_mem;\
0104    }while(0)\
0105 /**/
0106 
0107 /*!Inserts a new memory portions in the back of the chain*/
0108 #define BOOST_CONTAINER_MEMCHAIN_PUSH_FRONT(PMEMCHAIN, MEM)\
0109    do{\
0110       boost_cont_memchain *____chain____ = (PMEMCHAIN);\
0111       boost_cont_memchain_node *____tmp_mem____   = (boost_cont_memchain_node *)(MEM);\
0112       boost_cont_memchain *____root____  = &((PMEMCHAIN)->root_node);\
0113       if(!____chain____->root_node.next_node_ptr){\
0114          ____chain____->last_node_ptr = ____tmp_mem____;\
0115       }\
0116       boost_cont_memchain_node *____old_first____ = ____root____->next_node_ptr;\
0117       ____tmp_mem____->next_node_ptr = ____old_first____;\
0118       ____root____->next_node_ptr = ____tmp_mem____;\
0119       ++____chain____->num_mem;\
0120    }while(0)\
0121 /**/
0122 
0123 /*!Erases the memory portion after the portion pointed by BEFORE_IT from the memory chain*/
0124 /*!Precondition: BEFORE_IT must be a valid iterator of the memory chain and it can't be the end iterator*/
0125 #define BOOST_CONTAINER_MEMCHAIN_ERASE_AFTER(PMEMCHAIN, BEFORE_IT)\
0126    do{\
0127       boost_cont_memchain *____chain____ = (PMEMCHAIN);\
0128       boost_cont_memchain_node *____prev_node____  = (BEFORE_IT).node_ptr;\
0129       boost_cont_memchain_node *____erase_node____ = ____prev_node____->next_node_ptr;\
0130       if(____chain____->last_node_ptr == ____erase_node____){\
0131          ____chain____->last_node_ptr = &____chain____->root_node;\
0132       }\
0133       ____prev_node____->next_node_ptr = ____erase_node____->next_node_ptr;\
0134       --____chain____->num_mem;\
0135    }while(0)\
0136 /**/
0137 
0138 /*!Erases the first portion from the memory chain.
0139    Precondition: the memory chain must not be empty*/
0140 #define BOOST_CONTAINER_MEMCHAIN_POP_FRONT(PMEMCHAIN)\
0141    do{\
0142       boost_cont_memchain *____chain____ = (PMEMCHAIN);\
0143       boost_cont_memchain_node *____prev_node____  = &____chain____->root_node;\
0144       boost_cont_memchain_node *____erase_node____ = ____prev_node____->next_node_ptr;\
0145       if(____chain____->last_node_ptr == ____erase_node____){\
0146          ____chain____->last_node_ptr = &____chain____->root_node;\
0147       }\
0148       ____prev_node____->next_node_ptr = ____erase_node____->next_node_ptr;\
0149       --____chain____->num_mem;\
0150    }while(0)\
0151 /**/
0152 
0153 /*!Joins two memory chains inserting the portions of the second chain at the back of the first chain*/
0154 /*
0155 #define BOOST_CONTAINER_MEMCHAIN_SPLICE_BACK(PMEMCHAIN, PMEMCHAIN2)\
0156    do{\
0157       boost_cont_memchain *____chain____  = (PMEMCHAIN);\
0158       boost_cont_memchain *____chain2____ = (PMEMCHAIN2);\
0159       if(!____chain2____->root_node.next_node_ptr){\
0160          break;\
0161       }\
0162       else if(!____chain____->first_mem){\
0163          ____chain____->first_mem  = ____chain2____->first_mem;\
0164          ____chain____->last_node_ptr = ____chain2____->last_node_ptr;\
0165          ____chain____->num_mem  = ____chain2____->num_mem;\
0166          BOOST_CONTAINER_MEMCHAIN_INIT(*____chain2____);\
0167       }\
0168       else{\
0169          ____chain____->last_node_ptr->next_node_ptr = ____chain2____->first_mem;\
0170          ____chain____->last_node_ptr = ____chain2____->last_node_ptr;\
0171          ____chain____->num_mem += ____chain2____->num_mem;\
0172       }\
0173    }while(0)\*/
0174 /**/
0175 
0176 /*!Joins two memory chains inserting the portions of the second chain at the back of the first chain*/
0177 #define BOOST_CONTAINER_MEMCHAIN_INCORPORATE_AFTER(PMEMCHAIN, BEFORE_IT, FIRST, BEFORELAST, NUM)\
0178    do{\
0179       boost_cont_memchain *____chain____  = (PMEMCHAIN);\
0180       boost_cont_memchain_node *____pnode____  = (BEFORE_IT).node_ptr;\
0181       boost_cont_memchain_node *____next____   = ____pnode____->next_node_ptr;\
0182       boost_cont_memchain_node *____first____  = (boost_cont_memchain_node *)(FIRST);\
0183       boost_cont_memchain_node *____blast____  = (boost_cont_memchain_node *)(BEFORELAST);\
0184       size_t ____num____ = (NUM);\
0185       if(!____num____){\
0186          break;\
0187       }\
0188       if(____pnode____ == ____chain____->last_node_ptr){\
0189          ____chain____->last_node_ptr = ____blast____;\
0190       }\
0191       ____pnode____->next_node_ptr  = ____first____;\
0192       ____blast____->next_node_ptr  = ____next____;\
0193       ____chain____->num_mem  += ____num____;\
0194    }while(0)\
0195 /**/
0196 
0197 /*!Indicates the all elements allocated by boost_cont_multialloc_nodes or boost_cont_multialloc_arrays
0198    must be contiguous.*/
0199 #define BOOST_CONTAINER_DL_MULTIALLOC_ALL_CONTIGUOUS        ((size_t)(-1))
0200 
0201 /*!Indicates the number of contiguous elements allocated by boost_cont_multialloc_nodes or boost_cont_multialloc_arrays
0202    should be selected by those functions.*/
0203 #define BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS    ((size_t)(0))
0204 
0205 typedef struct boost_cont_malloc_stats_impl
0206 {
0207    size_t max_system_bytes;
0208    size_t system_bytes;
0209    size_t in_use_bytes;
0210 } boost_cont_malloc_stats_t;
0211 
0212 typedef unsigned int allocation_type;
0213 
0214 enum
0215 {
0216    // constants for allocation commands
0217    BOOST_CONTAINER_ALLOCATE_NEW          = 0X01,
0218    BOOST_CONTAINER_EXPAND_FWD            = 0X02,
0219    BOOST_CONTAINER_EXPAND_BWD            = 0X04,
0220    BOOST_CONTAINER_SHRINK_IN_PLACE       = 0X08,
0221    BOOST_CONTAINER_NOTHROW_ALLOCATION    = 0X10,
0222 //   BOOST_CONTAINER_ZERO_MEMORY           = 0X20,
0223    BOOST_CONTAINER_TRY_SHRINK_IN_PLACE   = 0X40,
0224    BOOST_CONTAINER_EXPAND_BOTH           = BOOST_CONTAINER_EXPAND_FWD | BOOST_CONTAINER_EXPAND_BWD,
0225    BOOST_CONTAINER_EXPAND_OR_NEW         = BOOST_CONTAINER_ALLOCATE_NEW | BOOST_CONTAINER_EXPAND_BOTH
0226 };
0227 
0228 //#define BOOST_CONTAINER_DLMALLOC_FOOTERS
0229 #ifndef BOOST_CONTAINER_DLMALLOC_FOOTERS
0230 enum {   BOOST_CONTAINER_ALLOCATION_PAYLOAD = sizeof(size_t)   };
0231 #else
0232 enum {   BOOST_CONTAINER_ALLOCATION_PAYLOAD = sizeof(size_t)*2   };
0233 #endif
0234 
0235 typedef struct boost_cont_command_ret_impl
0236 {
0237    void *first;
0238    int   second;
0239 }boost_cont_command_ret_t;
0240 
0241 size_t boost_cont_size(const void *p);
0242 
0243 void* boost_cont_malloc(size_t bytes);
0244 
0245 void  boost_cont_free(void* mem);
0246 
0247 void* boost_cont_memalign(size_t bytes, size_t alignment);
0248 
0249 int boost_cont_multialloc_nodes
0250    (size_t n_elements, size_t elem_size, size_t contiguous_elements, boost_cont_memchain *pchain);
0251 
0252 int boost_cont_multialloc_arrays
0253    (size_t n_elements, const size_t *sizes, size_t sizeof_element, size_t contiguous_elements, boost_cont_memchain *pchain);
0254 
0255 void boost_cont_multidealloc(boost_cont_memchain *pchain);
0256 
0257 size_t boost_cont_footprint();
0258 
0259 size_t boost_cont_allocated_memory();
0260 
0261 size_t boost_cont_chunksize(const void *p);
0262 
0263 int boost_cont_all_deallocated();
0264 
0265 boost_cont_malloc_stats_t boost_cont_malloc_stats();
0266 
0267 size_t boost_cont_in_use_memory();
0268 
0269 int boost_cont_trim(size_t pad);
0270 
0271 int boost_cont_mallopt(int parameter_number, int parameter_value);
0272 
0273 int boost_cont_grow
0274    (void* oldmem, size_t minbytes, size_t maxbytes, size_t *received);
0275 
0276 int boost_cont_shrink
0277    (void* oldmem, size_t minbytes, size_t maxbytes, size_t *received, int do_commit);
0278 
0279 void* boost_cont_alloc
0280    (size_t minbytes, size_t preferred_bytes, size_t *received_bytes);
0281 
0282 int boost_cont_malloc_check();
0283 
0284 boost_cont_command_ret_t boost_cont_allocation_command
0285    ( allocation_type command
0286    , size_t sizeof_object
0287    , size_t limit_objects
0288    , size_t preferred_objects
0289    , size_t *received_objects
0290    , void *reuse_ptr
0291    );
0292 
0293 void *boost_cont_sync_create();
0294 
0295 void boost_cont_sync_destroy(void *sync);
0296 
0297 int boost_cont_sync_lock(void *sync);
0298 
0299 void boost_cont_sync_unlock(void *sync);
0300 
0301 int boost_cont_global_sync_lock();
0302 
0303 void boost_cont_global_sync_unlock();
0304 
0305 #ifdef __cplusplus
0306 }  //extern "C" {
0307 #endif
0308 
0309 #ifdef _MSC_VER
0310 #pragma warning (pop)
0311 #endif
0312 
0313 
0314 #endif   //#define BOOST_CONTAINERDLMALLOC__EXT_H