Kym Object Allocation Fix #13

Merged
kayomn merged 3 commits from kym-object-alloc-fix into main 2023-06-03 22:07:19 +02:00
1 changed files with 6 additions and 5 deletions
Showing only changes of commit d8077d782d - Show all commits

View File

@ -7,11 +7,11 @@ const math = @import("./math.zig");
const std = @import("std"); const std = @import("std");
/// ///
/// Addressable mapping of integer values of type described by `index_int` to values of type `Value`. /// Addressable mapping of integers described by `index_int` to values of type `Value`.
/// ///
/// Slab maps are similar to slot maps in that they have O(1) insertion and removal, use a fragmented flat table /// Slab maps are similar to slot maps in that they have O(1) insertion and removal, however, use a flat table layout
/// structure instead. This reduces memory usage in some cases and can be useful for data that does not need to be /// instead of parallel arrays. This reduces memory usage in some cases and can be useful for data that does not need to
/// quickly iterated over, as values ordering is not guaranteed. /// be quickly iterated over, as values ordering is not guaranteed.
/// ///
/// *Note* `index_int` values may be as big or as small as desired per the use-case of the consumer, however, integers /// *Note* `index_int` values may be as big or as small as desired per the use-case of the consumer, however, integers
/// smaller than `usize` may result in the map reporting it is out of memory due to exhausting the addressable space /// smaller than `usize` may result in the map reporting it is out of memory due to exhausting the addressable space
@ -37,7 +37,7 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type
const Index = math.Int(index_int); const Index = math.Int(index_int);
/// ///
/// Slab type. /// Slab map type.
/// ///
const Self = @This(); const Self = @This();
@ -78,6 +78,7 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type
self.table = &.{}; self.table = &.{};
self.count = 0; self.count = 0;
kayomn marked this conversation as resolved
Review

free_index should be reset in here as well, otherwise re-uses of the data structure in future will have a corrupt initial state.

`free_index` should be reset in here as well, otherwise re-uses of the data structure in future will have a corrupt initial state.
self.free_index = 0;
} }
/// ///