aboutsummaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-09-28 21:25:14 +0100
committerGinger Bill <bill@gingerbill.org>2016-09-28 21:25:14 +0100
commit6e39a42c8a090d6e32231872cc292c90de6b304e (patch)
tree09d9375b92af5caf5cd6a5062e2b1422ab7e461d /code
parent5f6b0942f405f5595787ba3436e2e5410268e71e (diff)
Demo 004
Diffstat (limited to 'code')
-rw-r--r--code/demo.odin59
1 files changed, 55 insertions, 4 deletions
diff --git a/code/demo.odin b/code/demo.odin
index ba6532286..14f9f5b54 100644
--- a/code/demo.odin
+++ b/code/demo.odin
@@ -1,10 +1,61 @@
#import "fmt.odin"
#import "utf8.odin"
#import "hash.odin"
+#import "mem.odin"
main :: proc() {
- s := "Hello"
- fmt.println(s,
- utf8.valid_string(s),
- hash.murmur64(s.data, s.count))
+ { // New Standard Library stuff
+ s := "Hello"
+ fmt.println(s,
+ utf8.valid_string(s),
+ hash.murmur64(s.data, s.count))
+
+ // utf8.odin
+ // hash.odin
+ // - crc, fnv, fnva, murmur
+ // mem.odin
+ // - Custom allocators
+ // - Helpers
+ }
+
+ {
+ arena: mem.Arena
+ mem.init_arena_from_context(^arena, mem.megabytes(16)) // Uses default allocator
+ defer mem.free_arena(^arena)
+
+ push_allocator mem.arena_allocator(^arena) {
+ x := new(int)
+ x^ = 1337
+
+ fmt.println(x^)
+ }
+
+ /*
+ push_allocator x {
+ ...
+ }
+
+ is equivalent to this:
+
+ {
+ prev_allocator := current_context().allocator
+ current_context().allocator = x
+ defer current_context().allocator = prev_allocator
+
+ ...
+ }
+ */
+
+ // You can also "push" a context
+
+ c := current_context()
+ c.allocator = mem.arena_allocator(^arena)
+
+ push_context c {
+ x := new(int)
+ x^ = 365
+
+ fmt.println(x^)
+ }
+ }
}