I'm new to low level programming, my question may be dumb but I'm really not sure of what the behavior would be. When you use a FixedBufferAllocator, there's no way to free memory. So my question is when does the memory stored disappears ? Does it take place when the allocator gets out of scope or when the buffer gets out of scope or anything else ?
#Question about std.heap.FixedBufferAllocator
1 messages · Page 1 of 1 (latest)
thinking of memory as having lifetimes can be a useful model for how to think of the contract of allocators, and memory allocation in general
however, it's important to understand that these "lifetimes" are just that: a model, a useful construct that helps us design our programs in a simple, and hopefully efficient way
an allocator's job is to give you pointers to memory that you can use for whatever purposes you need
in the case of the fixed buffer allocator, it returns sub-pointers to a single buffer it is initialised with
in a manner of speaking, for the specific case of FBA, the lifetime of the pointers it returns are basically tied to the buffer
however, on broader scale, it's more generally useful to just treat the pointers as being tied to the lifetime of the allocator state
because as soon as the allocator state is destroyed, invalidated, or whatever else, the book keeping required to free the pointers no longer exists in a valid state, meaning the memory your pointers point to could already have been reclaimed, or be in use by other things that are unaware that you also have pointers to that memory
also, it should be noted that the FBA actually does have just enough book keeping to reclaim memory that you give back to it with free if you're freeing the latest allocation
ie fba.free(try fba.alloc(u8, 1)) should successfully have the fba in a state that's the same as before the alloc call