This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A simple illustration of a stream server that handles each client with a thread pool, and | |
| // if any worker returns an error then it prints out the errorReturnTrace. | |
| // | |
| // Untested. | |
| // | |
| // Written by Tetralux, 2023-11-15. | |
| const std = @import("std"); | |
| const Data = struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Ally = struct { | |
| data: ?*anyopaque, | |
| proc: *const fn( | |
| ally_data: ?*anyopaque, | |
| mode: Mode, | |
| count: usize, | |
| alignment: usize, | |
| old_memory: []u8, | |
| ) error{OutOfMemory}![]u8, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package util | |
| import "base:runtime" | |
| import "base:intrinsics" | |
| import "core:mem" | |
| import "core:mem/virtual" | |
| import "core:os" | |
| import "core:fmt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| A simple example of a linked list implementation that does NOT allocate the nodes individually. | |
| Written by TetraluxOnPC, 2024-07-28. | |
| */ | |
| package linked_list_example | |
| import "core:mem" | |
| import "core:mem/virtual" | |
| import "core:fmt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| A short demonstration of how atomized strings (strings turned into single ints to make comparison faster and storage simpler) can be serialised into a stream (or file), | |
| alongside the blobs that refer to them, without doing anything more than just memcpy'ing everything into the stream. | |
| It achieves this using the following techniques: | |
| 1) Atoms are stored in the Person structs only. They are i32s. | |
| 2) Atomizer turns strings into i32s by copying their length (u32le) into a buffer, followed by the string data. The current offset into the buffer is the atom for that string. | |
| 3) Both the slice of Persons and the atomizer's buffer can be directly written into a stream without alteration. See the comment in main() of the output. | |
| Written by Tetralux 2024-10-12. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define ZALLOCATOR_MODE_ALLOC 1 | |
| #define ZALLOCATOR_MODE_FREE 2 | |
| #define ZALLOCATOR_MODE_REALLOC 3 | |
| #define ZALLOCATOR_MODE_RESIZE 4 | |
| void *zallocator_interact(void *allocator, size_t mode, uint8_t should_zero, void *old_memory, size_t new_size); | |
| #define ch_stateful_malloc (ally, size) zallocator_interact(ally, ZALLOCATOR_MODE_ALLOC, false, NULL, size) | |
| #define ch_stateful_calloc (ally, size) zallocator_interact(ally, ZALLOCATOR_MODE_ALLOC, true, NULL, size) | |
| #define ch_stateful_realloc(ally, ptr, size) zallocator_interact(ally, ZALLOCATOR_MODE_REALLOC, false, ptr, size) | |
| #define ch_stateful_free (ally, ptr) (void)zallocator_interact(ally, ZALLOCATOR_MODE_FREE, false, ptr, 0) |
OlderNewer