If I were you, I would do the following:
- If the collision file is really large, read it in blocks until you get what you want.
- Use a memory pool to save blocks to avoid heap fragmentation during update / deletion.
- Then do the actual collision tests.
If you are trying to save data, you can save it as a structure.
struct Triangle { float vertices[9];
If the structures do not have the same size, it will be a little more complicated.
struct Triangle { int prevOffset;
Reading:
int offset = 0; char* m_Data;
You write structures as bytes while maintaining offsets.
// Writing the pool tri->next = ( (int)tri-(int)m_Data )+tri->Vertices.size()*4+16; // For a 32bit system // +12 for the ints (next/prev/id) // *4 for the floats
Exactly how memory pools bind their chunck headers. Using pointers to the previous and next elements so you can iterate in both directions .
source share