<div dir="ltr"><div><div><div><div><div><div>When reading binary file formats is there a way to do this that is performant? Can I mmap the file and then define arrays of structs that overlay the in memory structure?<br></div><br>Here is a longer explanation of what I mean.<br><br>So I tried writing a program that loads in 3d models from a binary format. The binary format has lots of arrays of structs that contains floats, and ints and so forth. So I defined a few helper functions<br><br>(define (read-n-things in n read-fun)<br>  (for/vector #:length n ([i (in-range n)]) (read-fun in)))<br><br></div>Then I would do stuff like this<br><br>(struct mesh-vertex (v n c st tangent int-bone-index float-bone-index))<br>(define (read-mesh-vertex in num-uv-layers has-tangent)<br>  (mesh-vertex <br>   (read-vector-3f in)<br>   (read-vector-3f in)<br>   (read-vector-4c in)<br>   (read-vector-nf in (* 2 num-uv-layers))<br>   (if has-tangent <br>       (read-n-things in (* num-uv-layers 4) read-float)<br>       #f)<br>   (read-n-things in 4 read-uint16)<br>   (read-n-things in 4 read-float)<br>  ))<br><br></div>and read-vector-3f and friends are like this<br><br>(define (read-vector-3f in)<br>  (read-n-things in 3 read-float))<br><br></div>and read-float is like this<br><br>(define (read-float in)<br>  (floating-point-bytes->real (read-bytes 4 in) #f))<br><br></div>The thing, this ends up being pretty slow. It takes seconds to load in a single model composed of on the order to 100k points.<br><br></div>Is there a way in racket to mmap the file into memory and read floats etc at given offsets. After reading the file it needs to be transformed into a suitable format for rendering with opengl. Right now I translate into a second in memory format suitable for feeding to opengl. Potentially if I can compute strides (memory distances between successive data points) easily then I can feed the model directly into opengl without transforming.<br><br>regards,<br><br>Richard. <br><div><br><br><div><div><div><br><br><div><div><br><br></div></div></div></div></div></div></div>