# Read!( ) not working for HDF5 file

**URL:** <https://discourse.julialang.org/t/read-not-working-for-hdf5-file/129722>\
**Category:** General Usage\
**Tags:** hdf5, memory-allocation, io\
**Created:** [June 7, 2025, 11:29am UTC](https://discourse.julialang.org/t/read-not-working-for-hdf5-file/129722 "2025-06-07T11:29:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 7, 2025, 11:29am UTC](https://discourse.julialang.org/t/read-not-working-for-hdf5-file/129722/1 "2025-06-07T11:29:10Z")

</div>

I have an HDF5 file. I want to read or allocate its data in variable `r` repeatedly instead of allocating in different places 💺 in memory.

```julia
using HDF5
fname = tempname(); # temporary file
fid = h5open(fname, "w")
create_group(fid, "mygroup")
fid["mydataset"] = rand(Float32, 18, 872)
r = zeros(Float32,18)
for i in 1:872
	read!((fid["mydataset"][:,1]), r)
end

```

i get following error.

> ERROR: MethodError: no method matching read!(::Vector{Float32}, ::Vector{Float32})  
> The function `read!` exists, but no method is defined for this combination of argument types.  
> Closest candidates are:  
> read!(::IO, ::StridedArray{T}) where T  
> @ Base io.jl:930  
> read!(::IO, ::AbstractArray{T}) where T  
> @ Base io.jl:911  
> read!(::AbstractString, ::Any)  
> @ Base io.jl:517

How to make it read on the same place in memory to reduce allocations?

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [June 15, 2025, 11:46am UTC](https://discourse.julialang.org/t/read-not-working-for-hdf5-file/129722/2 "2025-06-15T11:46:24Z")

</div>

Does HDF5.jl provide other function for reducing allocations? How will [`HDF5.select_hyperslab!()`](https://juliaio.github.io/HDF5.jl/stable/interface/dataspaces/#HDF5.select_hyperslab!) work for my case?
