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

  • Home
  • SEARCH
  • 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 3986332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:59:56+00:00 2026-05-20T05:59:56+00:00

I have a small question. I’m writing a loading/saving function for getting plain geometry

  • 0

I have a small question.

I’m writing a loading/saving function for getting plain geometry data from a saved file. The objects involved are instanced from classes with a lot of data in them, but they all use just plain old data, and no pointers/allocated memory and the like.

Is it possible to load the file into an allocated char* array, typecast that to, say, Geometry* , and safely expect everything to not get scrambled assuming I did the same reversed thing when saving (typecasting the array to char* and writing it to file)?

If I attempt to access the array when it is pointed to by a char* pointer, or a int*, or any other pointer type, is there any special considerations I need to take?

  • 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-20T05:59:57+00:00Added an answer on May 20, 2026 at 5:59 am

    Is it possible to load the file into
    an allocated char* array, typecast
    that to, say, Geometry*

    It’s possible. I’ve done a similar job. I had used two chained static_cast to do this, as:

    char *buffer;
    //..
    Geometry *g = static_cast<Geometry *>(static_cast<void*>(buffer));
    
    //reverse
    buffer = static_cast<char*>(static_cast<void*>(g));
    

    Since the two chained static_cast looks cumbersome, I’ve written this function template:

    template<class To, class From>
    To any_cast(From v)
    {
        return static_cast<To>(static_cast<void*>(v));
    }
    

    Then used it as,

    Geometry *g = any_cast<Geometry *>(buffer);
    
    //reverse
    buffer = any_cast<char*>(g);
    

    See this topic:

    Why do we have reinterpret_cast in C++ when two chained static_cast can do its job?

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

Sidebar

Related Questions

I have a small question: For example I'm using System.IO.File.Copy() method from .NET Framework.
I'm writing a small webapp in Grails and I have the following question regarding
I have a small utility that I use to download an MP3 file from
I have small question about pdp-11(simulator), I have this command (it begins from the
I have a small question in JavaScript. Here is a declaration: function answerToLifeUniverseAndEverything() {
I have an small question I didn't found an answer yet: how do I
I have a small JS function that does Ajax for me and another like
I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor()
I have a small question about structures with the LayoutKind.Explicit attribute set. I declared
I have a small question and I think this is asked before but I

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.