abstract type CVGSurface end
struct Triangle <: CVGSurface
triangleID :: Int64
x :: Float64
y :: Float64
z :: Float64
end
Triangle() = Triangle(1,1.0,1.0,1.0)
struct TrBoundry <:CVGSurface
triangleID1 :: Int64
triangleID2 :: Int64
triangleID3 :: Int64
boundryID ::Int64
end
TrBoundry() = TrBoundry(1,1,1,1)
struct Surface <: CVGSurface
n_max_vertex :: Int64
n_vertices :: Int64
n_triangles :: Int64
triangles :: Array{Triangle,1}
surfaces :: Array{TrBoundry,1}
end
function cvgseek2(file)
filestream = open(file)
fileline = readline(filestream)
n_max_vertex, n_vertices, n_triangles = parse.(Int,split(fileline))
triangles = Vector{Triangle}(undef,n_vertices)
trBoundry = Vector{TrBoundry}(undef,n_triangles)
for i in 1:n_vertices
pos = position(filestream)
seek(filestream, pos)
string_triangleID, string_xyz... = cvg_split(filestream)
triangleID = parse(Int,string_triangleID)
x, y, z = parse.(Float64,string_xyz)
triangles[i] = Triangle(triangleID, x, y, z)
end
for i in 1:n_triangles
pos = position(filestream)
seek(filestream, pos)
triangleID1, triangleID2, triangleID3, boundryID = parse.(Int, cvg_split(filestream))
trBoundry[i] = TrBoundry(triangleID1, triangleID2, triangleID3, boundryID)
end
return Surface(n_max_vertex, n_vertices, n_triangles, triangles, trBoundry)
end
“Files” like this
julia> @btime cvgseek2(files)
123.623 ms (144035 allocations: 15.89 MiB)
How to reduce allocation?