mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 12:48:14 +00:00
Merge remote-tracking branch 'offical/master'
This commit is contained in:
+1
-2
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
The `mem` package implements various allocators and provides utility procedures
|
||||
for dealing with memory, pointers and slices.
|
||||
Various allocators and provides helpers for dealing with memory, pointers and slices.
|
||||
|
||||
The documentation below describes basic concepts, applicable to the `mem`
|
||||
package.
|
||||
|
||||
@@ -18,6 +18,17 @@ Memory layout of the `cstring` type.
|
||||
*/
|
||||
Raw_Cstring :: runtime.Raw_Cstring
|
||||
|
||||
|
||||
/*
|
||||
Memory layout of the `string16` type.
|
||||
*/
|
||||
Raw_String16 :: runtime.Raw_String16
|
||||
|
||||
/*
|
||||
Memory layout of the `cstring16` type.
|
||||
*/
|
||||
Raw_Cstring16 :: runtime.Raw_Cstring16
|
||||
|
||||
/*
|
||||
Memory layout of `[]T` types.
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Two Level Segregated Fit memory allocator.
|
||||
package mem_tlsf
|
||||
|
||||
/*
|
||||
Copyright 2024 Jeroen van Rijn <nom@duclavier.com>.
|
||||
Made available under Odin's BSD-3 license.
|
||||
@@ -7,9 +10,6 @@
|
||||
Jeroen van Rijn: Source port
|
||||
*/
|
||||
|
||||
// package mem_tlsf implements a Two Level Segregated Fit memory allocator.
|
||||
package mem_tlsf
|
||||
|
||||
import "base:intrinsics"
|
||||
import "base:runtime"
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
A platform agnostic way to reserve/commit/decommit virtual memory.
|
||||
|
||||
|
||||
virtual.Arena usage
|
||||
|
||||
Example:
|
||||
// Source: https://github.com/odin-lang/examples/blob/master/arena_allocator/arena_allocator.odin
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
|
||||
// virtual package implements a multi-purpose arena allocator. If you are on a
|
||||
// platform that does not support virtual memory, then there is also a similar
|
||||
// arena in `core:mem`.
|
||||
import vmem "core:mem/virtual"
|
||||
|
||||
load_files :: proc() -> ([]string, vmem.Arena) {
|
||||
// This creates a growing virtual memory arena. It uses virtual memory and
|
||||
// can grow as things are added to it.
|
||||
arena: vmem.Arena
|
||||
arena_err := vmem.arena_init_growing(&arena)
|
||||
ensure(arena_err == nil)
|
||||
arena_alloc := vmem.arena_allocator(&arena)
|
||||
|
||||
// See arena_init_static for an arena that uses virtual memory, but cannot grow.
|
||||
|
||||
// See arena_init_buffer for an arena that does not use virtual memory,
|
||||
// instead it relies on you feeding it a buffer.
|
||||
|
||||
f1, f1_ok := os.read_entire_file("file1.txt", arena_alloc)
|
||||
ensure(f1_ok)
|
||||
|
||||
f2, f2_ok := os.read_entire_file("file2.txt", arena_alloc)
|
||||
ensure(f2_ok)
|
||||
|
||||
f3, f3_ok := os.read_entire_file("file3.txt", arena_alloc)
|
||||
ensure(f3_ok)
|
||||
|
||||
res := make([]string, 3, arena_alloc)
|
||||
res[0] = string(f1)
|
||||
res[1] = string(f2)
|
||||
res[2] = string(f3)
|
||||
|
||||
return res, arena
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
files, arena := load_files()
|
||||
|
||||
for f in files {
|
||||
fmt.println(f)
|
||||
}
|
||||
|
||||
// This deallocates everything that was allocated on the arena:
|
||||
// The loaded content of the files as well as the `files` slice.
|
||||
vmem.arena_destroy(&arena)
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
package mem_virtual
|
||||
|
||||
Reference in New Issue
Block a user