-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write a page on memory management, allocator scopes, for temporary allocator and arenas #58
Comments
My initial thoughts on this are to have multiple sections: AllocatorsSection describing all the current allocators with an example of how to acquire it and brief info of how it works. Using allocatorsThis should describe how to actually use an allocators once you have it. Memory allocation & freeingThis should maybe be first and should expand on the section you linked, mainly describing how you can allocate a piece of memory the C way (not caring about allocators, just using the default heap) and how to free it afterwards. This may sound simple to some, but will probably help most people get started with the basics. Also thinking about this, there should maybe be a small sub-section showing how to free stuff you get from std (DString, List, ...). |
I think with defer it's helpful but could be distracting, we should try and show the non-defer option then introduce the defer option with a link to that section then we can "take people with us" through that jump. Seems like a good set of ideas 👍 so far, I am currently on step 0, getting some more understanding of them at the moment (which will probably shape the content quite a bit based on what I found hard!) |
today I learned: module test;
import std::io;
fn void main()
{
DynamicArenaAllocator dynamic_arena;
dynamic_arena.init(4096, allocator::heap());
double *f = allocator::alloc(&dynamic_arena, double);
io::printfn("is this valid memory? %s", *f);
// TODO test out
/// double f[] = allocator::alloc_array(&dynamic_arena, double, 100);
// Release any dynamic arena memory.
dynamic_arena.free();
} also worth mentioning that you can do this globally inside main, then any nested function has the default allocator changed |
Temporary allocator:
@pool()
{
... temp allocations ...
}; // Temp allocations all are invalidated when exiting the scope
// variables declared inside the scope are no longer available, use after free is not possible |
Are there any good tools/techniques for finding/monitoring memory leaks or unsafe memory practices?
fn void main()
{
mem::@report_heap_allocs_in_scope()
{
start_stuff();
cleanup();
};
} |
We could do with a dedicated section on memory allocation, including allocator scopes, how to use the temporary allocator for which automatically frees
Expanding this content of this into a section like defer etc
include
@pool
and@scoped
macrosThe text was updated successfully, but these errors were encountered: