-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvmemalloc_small.h
More file actions
27 lines (22 loc) · 969 Bytes
/
vmemalloc_small.h
File metadata and controls
27 lines (22 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef VMEMALLOC_SMALL_GUARD
#define VMEMALLOC_SMALL_GUARD
// Semi arbitrary - need to balance container size so it's not too small or too large.
#define CHUNKS_PER_CONTAINER ((CHAR_BIT * sizeof(Word)) / 4)
// Container for lots of small chunks. Implemented as alloc'd chunk.
typedef union ContainerHeader {
struct {
// part of a linked list of containers.
union ContainerHeader* nextContainer;
// Bitmap where the nth bit represents the freeness of the nth chunk.
Word mask;
} s;
LARGEST_ALIGNMENT_TYPE padding;
} ContainerHeader;
// Returns a suitable chunk for use by a program.
// Fast but inefficient implementation for small chunks.
extern void* vmemallocSmall(int size);
// Frees a chunk used by a program so it can be re-used.
// Returns the amount of space saved or 0 if ptr wasn't created by vmemallocSmall.
// Fast but inefficient implementation for small chunks.
extern int vmemfreeSmall(void* ptr);
#endif