Created
July 28, 2020 09:45
-
-
Save lithdew/2f0233ee7769f675158ff6b3ff44a263 to your computer and use it in GitHub Desktop.
zig stack/heap
This file contains 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 std = @import("std"); | |
pub const KV = struct { | |
key: []const u8, | |
val: []const u8, | |
pub fn init(key: []const u8, val: []const u8) KV { | |
return KV{ .key = key, .val = val }; | |
} | |
}; | |
pub fn main() !void { | |
const kv = KV.init("this", "is on stack"); | |
var key = try std.heap.page_allocator.alloc(u8, 10); | |
var val = try std.heap.page_allocator.alloc(u8, 10); | |
const kv_2 = KV.init(key, val); | |
} | |
// pub const Hash = struct { | |
// const Self = @This(); | |
// inner: [std.crypto.Blake2s256.digest_length]u8, | |
// pub fn hash(data: []const u8) Self { | |
// var result: Self = undefined; | |
// std.crypto.Blake2s256.hash(data, &result.inner); | |
// return result; | |
// } | |
// }; | |
// pub fn main() !void { | |
// std.debug.print("{x} (size in bytes: {})\n", .{ Hash.hash("test123").inner, @sizeOf(Hash) }); | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment