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 693705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:46:52+00:00 2026-05-14T02:46:52+00:00

I am working on this project where I need to read in a lot

  • 0

I am working on this project where I need to read in a lot of data from .dat files and use the data to perform simulations. The data in my .dat file looks as follows:

DeviceID  InteractingDeviceID InteractionStartTime InteractionEndTime
  1            2                  1101                1105

1,2 1101 and 1105 are tab delimited and it means Device 1 interacted with Device 2 at 1101 ms and ended the interaction at 1105ms.

I have a trace data sets that compile thousands of such interactions and my job is to analyze these interactions.

The first step is to parse the file. The language of choice is C++. The approach I was thinking of taking was to read the file, for every line that’s read create a Device Object.
This Device object will contain the property DeviceId and an array/vector of structs, that will contain a list of all the devices the given DeviceId interacted with over the course of the simulation.The struct will contain the Interacting Device Id, Interaction Start Time and Interaction End Time.

I have a two fold question here:

  1. Is my approach correct?

  2. If I am on the right track, how do I rapidly parse these tab delimited data files and create Device objects without excessive memory overhead using C++?

A push in the right direction will be much appreciated.

Thanks

  • 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-14T02:46:53+00:00Added an answer on May 14, 2026 at 2:46 am

    Your approach seems to be correct given the information you’ve provided.

    I’m assuming you’d be creating a class something like:

    class device {
      public:
        int id;
        vector<interaction> interactions;
        void add_interaction(interaction add_me); // uses vector::insert
    };
    

    with

    typedef struct interaction_t {
        int other_device_id;
        int start_time;
        int end_time;
    } interaction;
    

    At that point, you should be able to read in the file, one line at a time, and pull out the data.

    device* pDev = NULL;
    interaction new_interaction;
    ifstream ifs( "data.dat" );
    char temp[MAX_LINE_LENGTH+1];
    int id, other_id, start, end;
    
    while(ifs.getline(temp, MAX_LINE_LENGTH)) {
        sscanf(temp, "%i\t%i\t%i\t%i",
            &id,
            &new_interaction.other_device_id,
            &new_interaction.start_time,
            &new_interaction.end_time);
        pDev = find_device_by_id(id);
        pDev->add_interaction(new_interaction);
    }
    

    Code is untested and for illustration purposes only, but you can get the idea. The trick would be writing the find_device_by_id function (would return a pointer to the device object with a matching id field). This shouldn’t require too heavy of a memory overhead per input line; if your input files are huge, you may not be able to store the data in memory and may have to store in a database instead.

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

Sidebar

Related Questions

In a project I'm working on, I need to read from a CSV file,
I'm working on a project and I need to read a CSV file and
Im working on a java project where i need to read some objects from
I really need an answer to this question. I am working on a project
My company is working on a project that needs to read XML files within
i'm working in a project where i need to read some values and send
This is the situation: I'm working on a project where I need to be
I'm currently working on a project in which i need to read some (Latitude,
In a project I'm working on I need to obtain a Gaussian fit from
I'm currently working on a project that involves a lot of text file reading.

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.