@@ -10,8 +10,10 @@ const windows = std.os.windows;
10
10
const Alignment = std .mem .Alignment ;
11
11
12
12
pub const ArenaAllocator = @import ("heap/arena_allocator.zig" ).ArenaAllocator ;
13
+ pub const BumpAllocator = @import ("heap/BumpAllocator.zig" );
13
14
pub const SmpAllocator = @import ("heap/SmpAllocator.zig" );
14
- pub const FixedBufferAllocator = @import ("heap/FixedBufferAllocator.zig" );
15
+ /// Deprecated; to be removed after 0.16.0 is tagged.
16
+ pub const FixedBufferAllocator = BumpAllocator ;
15
17
pub const PageAllocator = @import ("heap/PageAllocator.zig" );
16
18
pub const SbrkAllocator = @import ("heap/sbrk_allocator.zig" ).SbrkAllocator ;
17
19
pub const ThreadSafeAllocator = @import ("heap/ThreadSafeAllocator.zig" );
@@ -374,38 +376,36 @@ pub const wasm_allocator: Allocator = .{
374
376
};
375
377
376
378
/// Returns a `StackFallbackAllocator` allocating using either a
377
- /// `FixedBufferAllocator ` on an array of size `size` and falling back to
379
+ /// `BumpAllocator ` on an array of size `size` and falling back to
378
380
/// `fallback_allocator` if that fails.
379
381
pub fn stackFallback (comptime size : usize , fallback_allocator : Allocator ) StackFallbackAllocator (size ) {
380
382
return StackFallbackAllocator (size ){
381
383
.buffer = undefined ,
382
384
.fallback_allocator = fallback_allocator ,
383
- .fixed_buffer_allocator = undefined ,
385
+ .bump_allocator = undefined ,
384
386
};
385
387
}
386
388
387
389
/// An allocator that attempts to allocate using a
388
- /// `FixedBufferAllocator ` using an array of size `size`. If the
390
+ /// `BumpAllocator ` using an array of size `size`. If the
389
391
/// allocation fails, it will fall back to using
390
392
/// `fallback_allocator`. Easily created with `stackFallback`.
391
393
pub fn StackFallbackAllocator (comptime size : usize ) type {
392
394
return struct {
393
- const Self = @This ();
394
-
395
395
buffer : [size ]u8 ,
396
396
fallback_allocator : Allocator ,
397
- fixed_buffer_allocator : FixedBufferAllocator ,
397
+ bump_allocator : BumpAllocator ,
398
398
get_called : if (std .debug .runtime_safety ) bool else void =
399
399
if (std .debug .runtime_safety ) false else {},
400
400
401
401
/// This function both fetches a `Allocator` interface to this
402
402
/// allocator *and* resets the internal buffer allocator.
403
- pub fn get (self : * Self ) Allocator {
403
+ pub fn get (self : * @This () ) Allocator {
404
404
if (std .debug .runtime_safety ) {
405
405
assert (! self .get_called ); // `get` called multiple times; instead use `const allocator = stackFallback(N).get();`
406
406
self .get_called = true ;
407
407
}
408
- self .fixed_buffer_allocator = FixedBufferAllocator .init (self .buffer [0.. ]);
408
+ self .bump_allocator = .init (self .buffer [0.. ]);
409
409
return .{
410
410
.ptr = self ,
411
411
.vtable = &.{
@@ -429,8 +429,8 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
429
429
alignment : Alignment ,
430
430
ra : usize ,
431
431
) ? [* ]u8 {
432
- const self : * Self = @ptrCast (@alignCast (ctx ));
433
- return FixedBufferAllocator .alloc (& self .fixed_buffer_allocator , len , alignment , ra ) orelse
432
+ const self : * @This () = @ptrCast (@alignCast (ctx ));
433
+ return BumpAllocator .alloc (& self .bump_allocator , len , alignment , ra ) orelse
434
434
return self .fallback_allocator .rawAlloc (len , alignment , ra );
435
435
}
436
436
@@ -441,9 +441,9 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
441
441
new_len : usize ,
442
442
ra : usize ,
443
443
) bool {
444
- const self : * Self = @ptrCast (@alignCast (ctx ));
445
- if (self .fixed_buffer_allocator . ownsPtr (buf .ptr )) {
446
- return FixedBufferAllocator .resize (& self .fixed_buffer_allocator , buf , alignment , new_len , ra );
444
+ const self : * @This () = @ptrCast (@alignCast (ctx ));
445
+ if (mem . sliceOwnsPtr ( u8 , & self .buffer , @ptrCast (buf .ptr ) )) {
446
+ return BumpAllocator .resize (& self .bump_allocator , buf , alignment , new_len , ra );
447
447
} else {
448
448
return self .fallback_allocator .rawResize (buf , alignment , new_len , ra );
449
449
}
@@ -456,9 +456,9 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
456
456
new_len : usize ,
457
457
return_address : usize ,
458
458
) ? [* ]u8 {
459
- const self : * Self = @ptrCast (@alignCast (context ));
460
- if (self .fixed_buffer_allocator . ownsPtr (memory .ptr )) {
461
- return FixedBufferAllocator .remap (& self .fixed_buffer_allocator , memory , alignment , new_len , return_address );
459
+ const self : * @This () = @ptrCast (@alignCast (context ));
460
+ if (mem . sliceOwnsPtr ( u8 , & self .buffer , @ptrCast (memory .ptr ) )) {
461
+ return BumpAllocator .remap (& self .bump_allocator , memory , alignment , new_len , return_address );
462
462
} else {
463
463
return self .fallback_allocator .rawRemap (memory , alignment , new_len , return_address );
464
464
}
@@ -470,9 +470,9 @@ pub fn StackFallbackAllocator(comptime size: usize) type {
470
470
alignment : Alignment ,
471
471
ra : usize ,
472
472
) void {
473
- const self : * Self = @ptrCast (@alignCast (ctx ));
474
- if (self .fixed_buffer_allocator . ownsPtr (buf .ptr )) {
475
- return FixedBufferAllocator .free (& self .fixed_buffer_allocator , buf , alignment , ra );
473
+ const self : * @This () = @ptrCast (@alignCast (ctx ));
474
+ if (mem . sliceOwnsPtr ( u8 , & self .buffer , @ptrCast (buf .ptr ) )) {
475
+ return BumpAllocator .free (& self .bump_allocator , buf , alignment , ra );
476
476
} else {
477
477
return self .fallback_allocator .rawFree (buf , alignment , ra );
478
478
}
@@ -666,7 +666,7 @@ pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void {
666
666
const allocator = validationAllocator .allocator ();
667
667
668
668
var debug_buffer : [1000 ]u8 = undefined ;
669
- var fib = FixedBufferAllocator .init (& debug_buffer );
669
+ var fib : BumpAllocator = .init (& debug_buffer );
670
670
const debug_allocator = fib .allocator ();
671
671
672
672
const alloc_size = pageSize () * 2 + 50 ;
@@ -990,7 +990,7 @@ test {
990
990
_ = @import ("heap/memory_pool.zig" );
991
991
_ = ArenaAllocator ;
992
992
_ = GeneralPurposeAllocator ;
993
- _ = FixedBufferAllocator ;
993
+ _ = BumpAllocator ;
994
994
_ = ThreadSafeAllocator ;
995
995
_ = SbrkAllocator ;
996
996
if (builtin .target .cpu .arch .isWasm ()) {
0 commit comments