A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tlsf.h
Go to the documentation of this file.
1 #ifndef INCLUDED_tlsf
2 #define INCLUDED_tlsf
3 
4 /*
5 ** Two Level Segregated Fit memory allocator, version 3.1.
6 ** Written by Matthew Conte
7 ** http://tlsf.baisoku.org
8 **
9 ** Based on the original documentation by Miguel Masmano:
10 ** http://www.gii.upv.es/tlsf/main/docs
11 **
12 ** This implementation was written to the specification
13 ** of the document, therefore no GPL restrictions apply.
14 **
15 ** Copyright (c) 2006-2016, Matthew Conte
16 ** All rights reserved.
17 **
18 ** Redistribution and use in source and binary forms, with or without
19 ** modification, are permitted provided that the following conditions are met:
20 ** * Redistributions of source code must retain the above copyright
21 ** notice, this list of conditions and the following disclaimer.
22 ** * Redistributions in binary form must reproduce the above copyright
23 ** notice, this list of conditions and the following disclaimer in the
24 ** documentation and/or other materials provided with the distribution.
25 ** * Neither the name of the copyright holder nor the
26 ** names of its contributors may be used to endorse or promote products
27 ** derived from this software without specific prior written permission.
28 **
29 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31 ** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 ** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY
33 ** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 ** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 ** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40 
41 #include <stddef.h>
42 
43 /* tlsf_t: a TLSF structure. Can contain 1 to N pools. */
44 typedef void* tlsf_t;
45 
46 /* pool_t: a block of memory that TLSF can manage. */
47 typedef void* pool_t;
48 
50 
51 public:
52  /* Create/destroy a memory pool. */
53  tlsf_t tlsf_create(void* mem);
54  tlsf_t tlsf_create_with_pool(void* mem, size_t bytes);
55  void tlsf_destroy(tlsf_t tlsf);
57 
58  /* Add/remove memory pools. */
59  pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes);
60  void tlsf_remove_pool(tlsf_t tlsf, pool_t pool);
61 
62  /* malloc/memalign/realloc/free replacements. */
63  void* tlsf_malloc(tlsf_t tlsf, size_t bytes);
64  void* tlsf_mallocxz(tlsf_t tlsf, size_t bytes);
65  void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size);
66  void* tlsf_reallocxf(tlsf_t tlsf, void* ptr, size_t size);
67  void tlsf_free(tlsf_t tlsf, void* ptr);
68 
69  /* Returns internal block size, not original request size */
70  size_t tlsf_block_size(void* ptr);
71 
72  /* Overheads/limits of internal structures. */
73  size_t tlsf_size(void);
74  size_t tlsf_align_size(void);
75  size_t tlsf_block_size_min(void);
76  size_t tlsf_block_size_max(void);
77  size_t tlsf_pool_overhead(void);
78  size_t tlsf_alloc_overhead(void);
79 
80  /* Debugging. */
81  typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user);
82  void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user);
83  /* Returns nonzero if any internal consistency check fails. */
84  int tlsf_check(tlsf_t tlsf);
85  int tlsf_check_pool(pool_t pool);
86 };
87 
88 #endif
void * pool_t
Definition: tlsf.h:47
void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void *user)
Definition: tlsf.cc:776
int tlsf_check(tlsf_t tlsf)
Definition: tlsf.cc:719
size_t tlsf_alloc_overhead(void)
Definition: tlsf.cc:832
void tlsf_destroy(tlsf_t tlsf)
Definition: tlsf.cc:954
size_t tlsf_block_size_min(void)
Definition: tlsf.cc:815
void tlsf_free(tlsf_t tlsf, void *ptr)
Definition: tlsf.cc:980
size_t tlsf_align_size(void)
Definition: tlsf.cc:811
pool_t tlsf_get_pool(tlsf_t tlsf)
Definition: tlsf.cc:959
size_t tlsf_pool_overhead(void)
Definition: tlsf.cc:828
void * tlsf_mallocxz(tlsf_t tlsf, size_t bytes)
Definition: tlsf.cc:970
tlsf_t tlsf_create_with_pool(void *mem, size_t bytes)
Definition: tlsf.cc:948
pool_t tlsf_add_pool(tlsf_t tlsf, void *mem, size_t bytes)
Definition: tlsf.cc:836
size_t tlsf_block_size_max(void)
Definition: tlsf.cc:819
int tlsf_check_pool(pool_t pool)
Definition: tlsf.cc:795
size_t tlsf_size(void)
Definition: tlsf.cc:807
void(* tlsf_walker)(void *ptr, size_t size, int used, void *user)
Definition: tlsf.h:81
tlsf_t tlsf_create(void *mem)
Definition: tlsf.cc:926
void * tlsf_malloc(tlsf_t tlsf, size_t bytes)
Definition: tlsf.cc:963
size_t tlsf_block_size(void *ptr)
Definition: tlsf.cc:786
void * tlsf_t
Definition: tlsf.h:44
void * tlsf_reallocxf(tlsf_t tlsf, void *ptr, size_t size)
Definition: tlsf.cc:1065
void * tlsf_realloc(tlsf_t tlsf, void *ptr, size_t size)
Definition: tlsf.cc:1012
void tlsf_remove_pool(tlsf_t tlsf, pool_t pool)
Definition: tlsf.cc:881