From 97035cfc9cd0ff18c016fc12c1ec39814f924f32 Mon Sep 17 00:00:00 2001 From: "C.Brenhin Keller" Date: Fri, 4 Feb 2022 16:01:52 -0500 Subject: [PATCH 1/4] Add new inner constructor for when you already have an NTuple of data --- src/ManualMemory.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ManualMemory.jl b/src/ManualMemory.jl index 9b68dd0..5ecc335 100644 --- a/src/ManualMemory.jl +++ b/src/ManualMemory.jl @@ -6,6 +6,10 @@ mutable struct MemoryBuffer{N,T} @assert Base.allocatedinline(T) new{N,T}() end + @inline function MemoryBuffer(data::NTuple{N,T}) where {N,T} + @assert Base.allocatedinline(T) + new{N,T}(data) + end end @inline Base.unsafe_convert(::Type{Ptr{T}}, m::MemoryBuffer) where {T} = Ptr{T}(pointer_from_objref(m)) @inline Base.pointer(m::MemoryBuffer{N,T}) where {N,T} = Ptr{T}(pointer_from_objref(m)) From de1b04249e5690273f2409085579868158c9b3c4 Mon Sep 17 00:00:00 2001 From: "C.Brenhin Keller" Date: Fri, 4 Feb 2022 16:09:19 -0500 Subject: [PATCH 2/4] Add test for new inner constructor --- test/runtests.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7fc1516..6854a6c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,8 +31,11 @@ using Test store!(pointer(x), 1) @test load(pointer(x)) === 1 === load(pointer(y)) end + + # Test construction with existing data + s = (1,2,3,4,5) + @test MemoryBuffer(s).data === s end using ThreadingUtilities include(joinpath(pkgdir(ThreadingUtilities), "test", "runtests.jl")) - From 144097654715f41d170c80d94ff2fd97e61d8c0d Mon Sep 17 00:00:00 2001 From: "C.Brenhin Keller" Date: Fri, 4 Feb 2022 16:38:09 -0500 Subject: [PATCH 3/4] Add a few examples to README --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 860615a..878e620 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,35 @@ [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaSIMD.github.io/ManualMemory.jl/dev) [![Build Status](https://github.com/JuliaSIMD/ManualMemory.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/JuliaSIMD/ManualMemory.jl/actions/workflows/CI.yml) [![Coverage](https://codecov.io/gh/JuliaSIMD/ManualMemory.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/JuliaSIMD/ManualMemory.jl) + +Manually managed memory buffers backed by NTuples + +### Examples + +```julia +julia> using ManualMemory: MemoryBuffer, load, store!, LazyPreserve, preserve, PseudoPtr, Reference + +julia> m = MemoryBuffer{4,Float64}(undef) +MemoryBuffer{4, Float64}((2.283825594e-314, 2.2157350003e-314, 2.216358792e-314, 2.08e-322)) + +julia> store!(pointer(m), 1.23) + +julia> load(pointer(m)) +1.23 +``` +Specifying an existing `NTuple` of data: +```julia +julia> s = (1,2,3,4,5); + +julia> m = MemoryBuffer(s) +MemoryBuffer{5, Int64}((1, 2, 3, 4, 5)) + +julia> load(p) +1 + +julia> load(p+sizeof(Int64)) +2 + +julia> load(p+sizeof(Int64)*2) +3 +``` From cd5c22c0a9f9edec4280f4ac885fc7030a1b81ad Mon Sep 17 00:00:00 2001 From: "C.Brenhin Keller" Date: Fri, 4 Feb 2022 16:45:03 -0500 Subject: [PATCH 4/4] Bump version number, I suppose --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f760ecc..f194eeb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ManualMemory" uuid = "d125e4d3-2237-4719-b19c-fa641b8a4667" authors = ["chriselrod and contributors"] -version = "0.1.6" +version = "0.1.7" [compat] julia = "1.5"