Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 244579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:01:00+00:00 2026-05-11T21:01:00+00:00

I need to write a file format that writes out data to a file

  • 0

I need to write a file format that writes out data to a file and can read it back.

It should be able to read the data back fairly fast, which should involve blitting a large block of data into a std::vector (since their storage is always implemented contiguously).

However, when writing the file, I have no idea how to enforce constraints on alignment and size of ints and other types.

How should this be done? I’m using gcc on buntu linux on Q6600 (x86).

Just as an example:

struct Vertex
{
  float point [3];
  float normal [3];
  float texcoord [2];
}

Later on, the data is stored in a std::vector<Vertex>. I have thought about using __attribute__ and packing / aligning it so that it will be more portable across different platforms.

edit:
I’ve already made a specification, and I intend to use it. The largest bits of data are the Vertex and Indices, so those will be read as big blocks, and for example (one part of a larger spec):
A VertexGroup is a group of vertices who share a characteristic. They can only hold one material at a time, so there should be many of them contained in a mesh.

<uint> thisid # Of this VertexGroup
<string> name
<uint> materialId # A material
<uint> vertexCount
for (vetexCount):
    <3xfloat> point
    <3xfloat> normal
    <2xfloat> texcoord
<uint> triangleCount
for (triangleCount):
    <3xuint> indices
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:01:00+00:00Added an answer on May 11, 2026 at 9:01 pm

    This will depend on your compiler and platform. As far as I know, there is no way to enforce this in a completely cross-compiler and cross-platform manner, without defining lots of macros of your own.

    However, both VC++ and GCC (the big two) support the #pragma pack directive, which will allow you to define the alignment and packing for your struct. See http://msdn.microsoft.com/en-us/library/2e70t5y1.aspx or http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html.

    With that in mind, you can use #pragma pack to define how your structure is aligned, then fread() or similar to simply blit the bytes from the file to memory. You may want to prefix the list with the list length so that you can allocate the memory for the whole list at once, then load the entire file using a single I/O call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with Quickbook's IIF file format and I need to write a parser
I need to write a string into a file. For that, my code is:
I'm trying to write data to a file in binary format for compression. The
I need a way to write an excel file with format through Pure PHP.
I need to write a rule to redirect any image file to a specific
I need to write an error log to a XML file using Visual Basic
I need to generate an XML file in C#. I want to write the
Using ASP.net, how do you write ANSI characters to a text file? I need
I need write an update statement that used multiple tables to determine which rows
I need to write a Java Comparator class that compares Strings, however with one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.