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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:35:06+00:00 2026-06-08T13:35:06+00:00

I was working in my file loader, and i decided it was better for

  • 0

I was working in my file loader, and i decided it was better for the next updates instead of keep using fread and fseek read the hole file to a BYTE buffer, and so did i, now i was wondering if theres no easy way of assigning part of this BYTE buffer to an structure.

I Already tried making a temp buffer with the same size as the structure, copy all the BYTE i need from the original buffer to it, and use memcpy, but it didn’t work right, i just received a lot of random numbers (which i think i am receiving their pointers, but i don’t know right).

Thank you for your time!

Edit: REAL Code

void memread(BYTE from[],int pos, void * to,size_t size) 
{   
    BYTE * temp = new BYTE[sizeof(BYTE)*size];

    for (unsigned int i = 0; i< 1+size; i++)
        temp[i] = from[i+pos];

    memcpy(to,temp,size);

}


... inside the file loader ...


fseek(fl,0,SEEK_END);
const int memory_size = (int)ftell(fl);


BYTE * memory = new BYTE[sizeof(BYTE)*memory_size];
fseek(fl,0,SEEK_SET);

for (int i=1;i<=memory_size;i++)
fread(&memory[i],sizeof(BYTE),1,fl);

fclose(fl);

int memory_pos = 0;

XM::Memory xm;
memset(&xm,0,sizeof(XM::Memory));


memread(memory,1,&xm.Header,sizeof(XM::Header));
  • 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-06-08T13:35:08+00:00Added an answer on June 8, 2026 at 1:35 pm

    First you are reading the file byte by byte, which will give you a bad performance. Next, your memread (where you don’t free the temp buffer!) can be replaced by a simple memcpy

    fseek(fl, 0, SEEK_END); 
    const int memory_size = (int)ftell(fl); 
    
    BYTE* memory = new BYTE[sizeof(BYTE) * memory_size];
    fseek(fl, 0, SEEK_SET); 
    
    fread(memory, sizeof(BYTE), memory_size, fl); 
    
    fclose(fl); 
    
    int memory_pos = 0; 
    
    XM::Memory xm;
    memset(&xm, 0, sizeof(XM::Memory)); 
    
    memcpy(&xm.Header, memory + memory_pos, sizeof(XM::Header);
    

    Never forget to delete[] your allocated arrays like temp and memory

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

Sidebar

Related Questions

I working on adding file uploading to my web application. I'm using an iframe
I'm working on a file format that should be written and read in several
I'm working on a google maps loader (using the google maps javascript API). I
I am working on a data loader, implemented using Spring Batch i.e. reading multiple
I have a working file rename java tool, now I want to add an
Am working on file / folder event capturing of OS X 10.5 and 10.6
On whatever reason this is not working (says 'file not found'), set in=c:\myprogram\_save cd
This is my first time working with file i/o in java, and it's not
I am working on pom file modifications to change the version node value. I
I am working with a file (fasta file), here is the format- >chr1 AACCCCCCCCTCCCCCCGCTTCTGGCCACAGCACTTAAACACATCTCTGC

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.