Memory allocation in broadcast assignment

You could use Array types where the size is known at compile time.

For example https://github.com/JuliaArrays/StaticArrays.jl
or (if only a few dimensions are static)
https://github.com/mateuszbaran/HybridArrays.jl

It could be that this array type is not flexible enough for your situation.
Maybe there is also an easier way to speed this up.

Notice that the proposed functions are not really in-place.

using StaticArrays, BenchmarkTools

function f1_s!(arr, p)
    fp1, fp2 = floor.((p[1], p[2]))
    cp1, cp2 = ceil.((p[1], p[2]))
    arr = @SArray [fp1 fp2 fp1 fp2 ; cp1 cp1 cp2 cp2]
end

arr = zeros(2, 4)
arr_s = @SArray zeros(2, 4)
p = [1.3, 6.8]
p_s = @SArray [1.3, 6.8]

@benchmark f1!($arr, $p)
BenchmarkTools.Trial: 
  memory estimate:  272 bytes
  allocs estimate:  9
  --------------
  minimum time:     94.080 ns (0.00% GC)
  median time:      99.577 ns (0.00% GC)
  mean time:        119.891 ns (6.83% GC)
  maximum time:     2.611 μs (91.40% GC)
  --------------
  samples:          10000
  evals/sample:     946

@benchmark f1_s!($arr_s, $p)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     4.099 ns (0.00% GC)
  median time:      4.701 ns (0.00% GC)
  mean time:        4.883 ns (0.00% GC)
  maximum time:     405.500 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1000

### EDIT: see the answer form Skoffer, the following benchmark is not realistic. (But I leave it here for reference).
@benchmark f1_s!($arr_s, $p_s)
BenchmarkTools.Trial: 
  memory estimate:  0 bytes
  allocs estimate:  0
  --------------
  minimum time:     0.399 ns (0.00% GC)
  median time:      0.500 ns (0.00% GC)
  mean time:        0.512 ns (0.00% GC)
  maximum time:     15.000 ns (0.00% GC)
  --------------
  samples:          10000
  evals/sample:     1000
4 Likes