tommyalloc.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2// Copyright (C) 2010 Andrea Mazzoleni
3
8#ifndef TOMMY_ALLOC_H
9#define TOMMY_ALLOC_H
10
11#include "tommytypes.h"
12
13/******************************************************************************/
14/* allocator */
15
19struct tommy_allocator_entry_struct {
20 struct tommy_allocator_entry_struct* next;
21};
22typedef struct tommy_allocator_entry_struct tommy_allocator_entry;
23
27typedef struct tommy_allocator_struct {
28 struct tommy_allocator_entry_struct* free_block;
29 struct tommy_allocator_entry_struct* used_segment;
34
43TOMMY_API void tommy_allocator_init(tommy_allocator* alloc, tommy_size_t block_size, tommy_size_t align_size);
44
51
61
67TOMMY_API void* tommy_allocator_alloc(tommy_allocator* alloc);
68
75TOMMY_API void tommy_allocator_free(tommy_allocator* alloc, void* ptr);
76
84
85#endif
86
Allocator of fixed-size blocks.
Definition: tommyalloc.h:27
struct tommy_allocator_entry_struct * free_block
List of free blocks.
Definition: tommyalloc.h:28
struct tommy_allocator_entry_struct * used_segment
List of allocated segments.
Definition: tommyalloc.h:29
tommy_size_t count
Number of allocated blocks.
Definition: tommyalloc.h:32
tommy_size_t block_size
Block size.
Definition: tommyalloc.h:30
tommy_size_t align_size
Alignment size.
Definition: tommyalloc.h:31
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 void * tommy_allocator_alloc(tommy_allocator *alloc)
Allocates a block.
struct tommy_allocator_struct tommy_allocator
Allocator of fixed-size blocks.
TOMMY_API tommy_size_t tommy_allocator_memory_usage(const tommy_allocator *alloc)
Gets the total size of allocated blocks currently in use.
TOMMY_API void tommy_allocator_init(tommy_allocator *alloc, tommy_size_t block_size, tommy_size_t align_size)
Initializes the allocator.
TOMMY_API void tommy_allocator_clear(tommy_allocator *alloc)
Releases all the allocated memory to the heap, including blocks still in use.
Generic types.
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:40