Formatting.
This commit is contained in:
parent
5f0ef9c0dd
commit
b4cfc14d3b
@ -5,29 +5,29 @@ AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
PadOperators: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments: true
|
||||
|
@ -1,6 +1,21 @@
|
||||
#ifndef BASE_ARENA_H
|
||||
#define BASE_ARENA_H
|
||||
|
||||
// Arena allocator simulates how stack memory works.
|
||||
// This allows us the ability to allocate a reasonableamount of memory
|
||||
// at startup and only use that allocated amount of memory throughout
|
||||
// the lifetime of the application. Obviously this still uses
|
||||
// "malloc, free, VirtualAlloc, VirtualFree" but instead of having to
|
||||
// request and freeing memory during runtime, we create an environment
|
||||
// where we have as much memory we could ever need and them portion it
|
||||
// out in small chunk as needed. This has multiple benefits that would
|
||||
// make itself glaring throughout the codebase but the gist of it is that
|
||||
// we have one large block of memory throughout the lifetime,
|
||||
// then application specific code that could need memory grab a chunck
|
||||
// memory from the big block of memory we have reserved with the operating
|
||||
// system at startup do whatever operation it needs to do, then return
|
||||
// that block of memory back to the arena.
|
||||
|
||||
// Constants
|
||||
#define ARENA_HEADER_SIZE 64
|
||||
|
||||
@ -11,28 +26,28 @@ enum { ArenaFlag_NoChain = (1 << 0); ArenaFlag_LargePages = (1 << 1); };
|
||||
typedef struct ArenaParams ArenaParams;
|
||||
struct ArenaParams {
|
||||
ArenaFlags flags;
|
||||
u64 reserve_size;
|
||||
u64 commite_size;
|
||||
void *optional_backing_buffer; // NOTE(tijani): ??
|
||||
u64 reserve_size;
|
||||
u64 commite_size;
|
||||
void *optional_backing_buffer; // NOTE(tijani): ??
|
||||
};
|
||||
|
||||
typedef struct Arena Arena;
|
||||
struct Arena {
|
||||
Arena *previous; // Previous arena in the chain
|
||||
Arena *current; // Current arena in the chain
|
||||
Arena *previous; // Previous arena in the chain
|
||||
Arena *current; // Current arena in the chain
|
||||
ArenaFlags flags;
|
||||
u32 commit_size;
|
||||
u64 reserve_size;
|
||||
u64 base_position;
|
||||
u64 position;
|
||||
u64 commit;
|
||||
u64 reserve;
|
||||
u32 commit_size;
|
||||
u64 reserve_size;
|
||||
u64 base_position;
|
||||
u64 position;
|
||||
u64 commit;
|
||||
u64 reserve;
|
||||
};
|
||||
|
||||
typedef struct Temp Temp;
|
||||
struct Temp {
|
||||
Arena *arena;
|
||||
u64 position;
|
||||
u64 position;
|
||||
};
|
||||
|
||||
// creation, destruction
|
||||
@ -42,14 +57,14 @@ internal void arena_releas(Arena *arena);
|
||||
|
||||
// push, pop operations
|
||||
internal void *arena_psuh(Arena *arena, u64 size, u64 align);
|
||||
internal u64 arena_position(Arena *arena);
|
||||
internal void arena_pop_to(Arena *arena, u64 position);
|
||||
internal void arena_clear(Arena *arena);
|
||||
internal void arena_pop(Arena *arena, u64 amount);
|
||||
internal u64 arena_position(Arena *arena);
|
||||
internal void arena_pop_to(Arena *arena, u64 position);
|
||||
internal void arena_clear(Arena *arena);
|
||||
internal void arena_pop(Arena *arena, u64 amount);
|
||||
#define push_array_no_zero_aligned(a, T, c, align) (T *)arena_push((a), sizeof(T) * (c), (align))
|
||||
#define push_array_aligned(a, T, c, align) (T *)MemoryZero(push_array_no_zero_aligned(a, T, c, align), sizeof(T) * (c))
|
||||
#define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, Align_Of(T)))
|
||||
#define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, Align_Of(T)))
|
||||
#define push_array_aligned(a, T, c, align) (T *)MemoryZero(push_array_no_zero_aligned(a, T, c, align), sizeof(T) * (c))
|
||||
#define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, Align_Of(T)))
|
||||
#define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, Align_Of(T)))
|
||||
|
||||
// Temp
|
||||
internal Temp temp_begin(Arena *arena);
|
||||
|
@ -6,37 +6,37 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define global static
|
||||
#define local static
|
||||
#define global static
|
||||
#define local static
|
||||
#define internal static
|
||||
|
||||
// Base Types
|
||||
typedef uint8_t u8;
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
|
||||
typedef s8 b8;
|
||||
typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
typedef s64 b64;
|
||||
typedef s8 b8;
|
||||
typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
typedef s64 b64;
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
// Units
|
||||
#define KB(n) (((u64)(n)) << 10)
|
||||
#define MB(n) (((u64)(n)) << 20)
|
||||
#define GB(n) (((u64)(n)) << 30)
|
||||
#define TB(n) (((u64)(n)) << 40)
|
||||
#define KB(n) (((u64)(n)) << 10)
|
||||
#define MB(n) (((u64)(n)) << 20)
|
||||
#define GB(n) (((u64)(n)) << 30)
|
||||
#define TB(n) (((u64)(n)) << 40)
|
||||
#define Thousand(n) ((n) * 1000)
|
||||
#define Million(n) ((n) * 1000000)
|
||||
#define Billion(n) ((n) * 1000000000)
|
||||
#define Million(n) ((n) * 1000000)
|
||||
#define Billion(n) ((n) * 1000000000)
|
||||
|
||||
// Memory operations
|
||||
#define MemoryZero(dest, count) memset((dest), 0, (count))
|
||||
@ -56,4 +56,9 @@ typedef double f64;
|
||||
// ??(tijani): the calculation of how this works breaks my brain, need to bust out the pen and paper to figure it out.
|
||||
#define AlignPow2(x, b) (((x) + (b) - 1) & (~((b) - 1)))
|
||||
|
||||
// Linkedlist building macros
|
||||
|
||||
// Singlely linked lists (stacks)
|
||||
#define SLLStackPush_N(head, new_node, next) ((new_node)->next = (head), (head) = (new_node))
|
||||
#define SLLStackPop_N(head, next) ((head) = (head)->next)
|
||||
#endif // BASE_CORE_H
|
||||
|
@ -12,15 +12,15 @@ struct String8 {
|
||||
typedef struct String8Node String8Node;
|
||||
struct String8Node {
|
||||
String8Node *next;
|
||||
String8 string;
|
||||
String8 string;
|
||||
};
|
||||
|
||||
typedef struct String8List String8List;
|
||||
struct String8List {
|
||||
String8Node *first;
|
||||
String8Node *last;
|
||||
u64 node_count;
|
||||
u64 total_size;
|
||||
u64 node_count;
|
||||
u64 total_size;
|
||||
};
|
||||
|
||||
#endif // BASE_STRINGS_H
|
||||
|
@ -4,39 +4,39 @@
|
||||
// System Information
|
||||
typedef struct OS_SystemInfo OS_SystemInfo;
|
||||
struct OS_SystemInfo {
|
||||
u32 logical_processor_count;
|
||||
u64 page_size;
|
||||
u64 large_page_size;
|
||||
u64 allocation_granularity; // NOTE(tijani): ??? What does this mean?
|
||||
u32 logical_processor_count;
|
||||
u64 page_size;
|
||||
u64 large_page_size;
|
||||
u64 allocation_granularity; // NOTE(tijani): ??? What does this mean?
|
||||
String8 machine_name;
|
||||
};
|
||||
|
||||
// Process Information
|
||||
typedef struct OS_ProcessInfo OS_ProcessInfo;
|
||||
struct OS_ProcessInfo {
|
||||
u32 process_id;
|
||||
String8 binary_path;
|
||||
String8 initial_path;
|
||||
String8 user_program_data_path;
|
||||
u32 process_id;
|
||||
String8 binary_path;
|
||||
String8 initial_path;
|
||||
String8 user_program_data_path;
|
||||
String8List module_load_paths;
|
||||
String8List environment;
|
||||
};
|
||||
|
||||
// %os_hooks(implemented per-os) System and process info
|
||||
internal OS_SystemInfo *os_get_system_info(void);
|
||||
internal OS_SystemInfo *os_get_system_info(void);
|
||||
internal OS_ProcessInfo *os_get_process_info(void);
|
||||
internal String8 os_get_current_path(Arena *arena);
|
||||
internal String8 os_get_current_path(Arena *arena);
|
||||
|
||||
// %os_hooks(implemented per-os) Memory allocation
|
||||
|
||||
// NOTE(tijani): For normal page size
|
||||
internal b32 os_commit(void *ptr, u64 size);
|
||||
internal b32 os_commit(void *ptr, u64 size);
|
||||
internal void *os_reserve(u64 size);
|
||||
internal void os_decommit(void *ptr, u64 size);
|
||||
internal void os_release(void *ptr, u64 size);
|
||||
internal void os_decommit(void *ptr, u64 size);
|
||||
internal void os_release(void *ptr, u64 size);
|
||||
|
||||
// NOTE(tijani): For large page size
|
||||
internal void *os_reserve_large(u64 size);
|
||||
internal b32 os_commit_large(void *ptr, u64 size);
|
||||
internal b32 os_commit_large(void *ptr, u64 size);
|
||||
|
||||
#endif // OS_CORE_H
|
||||
|
@ -1,9 +1,9 @@
|
||||
// %os_hooks(implemented per-os) System and process info
|
||||
internal OS_SystemInfo *os_get_system_info(void) { return &os_w32_state.system_info; }
|
||||
internal OS_SystemInfo *os_get_system_info(void) { return &os_w32_state.system_info; }
|
||||
|
||||
internal OS_ProcessInfo *os_get_process_info(void) { return &os_w32_state.process_info; }
|
||||
|
||||
internal String8 os_get_current_path(Arena *arena) {}
|
||||
internal String8 os_get_current_path(Arena *arena) {}
|
||||
|
||||
// %os_hooks(implemented per-os) Memory allocation
|
||||
|
||||
|
@ -9,9 +9,9 @@ struct OS_W32_State {
|
||||
Arena *arena;
|
||||
|
||||
// System information
|
||||
OS_SystemInfo system_info;
|
||||
OS_SystemInfo system_info;
|
||||
OS_ProcessInfo process_info;
|
||||
u64 microsecond_resolution;
|
||||
u64 microsecond_resolution;
|
||||
};
|
||||
|
||||
// Globals
|
||||
|
Loading…
Reference in New Issue
Block a user