https://github.com/fluxml/alloc.jl
https://github.com/fluxml/alloc.jl
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/fluxml/alloc.jl
- Owner: FluxML
- Created: 2018-08-02T12:14:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-17T13:18:25.000Z (over 6 years ago)
- Last Synced: 2025-02-27T03:50:04.007Z (over 1 year ago)
- Language: Julia
- Size: 12.7 KB
- Stars: 27
- Watchers: 7
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Alloc.jl
Alloc.jl makes Julia's memory allocator customisable. Currently it provides the ability to bump allocate everything within a block of code.
```julia
julia> using IRTools
julia> using Alloc: Buffer, run, profile
julia> function f()
x = rand(100, 100)
y = rand(100)
x*y
end
f (generic function with 1 method)
julia> @allocated f()
81872
julia> profile(f); # Figure out how big our buffer should be
[ Info: Allocated 81600 bytes
julia> const buf = Buffer(10^6);
julia> @allocated run(f, buf)
1280
```
The bump allocator has the downside that no memory is ever freed until `f` is finished. The advantage is that allocation is _really_ fast (effectively the same as stack allocation of arrays), so if your memory usage is reasonably predictable you can just bump allocate within your main loop.