tommyalloc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, Andrea Mazzoleni. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
32#ifndef __TOMMYALLOC_H
33#define __TOMMYALLOC_H
34
35#include "tommytypes.h"
36
37/******************************************************************************/
38/* allocator */
39
43struct tommy_allocator_entry_struct {
44 struct tommy_allocator_entry_struct* next;
45};
46typedef struct tommy_allocator_entry_struct tommy_allocator_entry;
47
51typedef struct tommy_allocator_struct {
52 struct tommy_allocator_entry_struct* free_block;
53 struct tommy_allocator_entry_struct* used_segment;
58
65TOMMY_API void tommy_allocator_init(tommy_allocator* alloc, tommy_size_t block_size, tommy_size_t align_size);
66
73
78TOMMY_API void* tommy_allocator_alloc(tommy_allocator* alloc);
79
86TOMMY_API void tommy_allocator_free(tommy_allocator* alloc, void* ptr);
87
93
94#endif
Allocator of fixed size blocks.
Definition: tommyalloc.h:51
struct tommy_allocator_entry_struct * free_block
List of free blocks.
Definition: tommyalloc.h:52
struct tommy_allocator_entry_struct * used_segment
List of allocated segments.
Definition: tommyalloc.h:53
tommy_size_t count
Number of allocated elements.
Definition: tommyalloc.h:56
tommy_size_t block_size
Block size.
Definition: tommyalloc.h:54
tommy_size_t align_size
Alignment size.
Definition: tommyalloc.h:55
TOMMY_API void tommy_allocator_free(tommy_allocator *alloc, void *ptr)
Deallocates a block.
TOMMY_API void tommy_allocator_done(tommy_allocator *alloc)
Deinitializes the allocator.
TOMMY_API tommy_size_t tommy_allocator_memory_usage(tommy_allocator *alloc)
Gets the size of allocated memory.
TOMMY_API void * tommy_allocator_alloc(tommy_allocator *alloc)
Allocates a block.
struct tommy_allocator_struct tommy_allocator
Allocator of fixed size blocks.
TOMMY_API void tommy_allocator_init(tommy_allocator *alloc, tommy_size_t block_size, tommy_size_t align_size)
Initializes the allocator.
Generic types.
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:60