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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:40:12+00:00 2026-05-31T01:40:12+00:00

I have a buffer with n bytes, but I only want read in sizeof(something)

  • 0

I have a buffer with n bytes, but I only want read in sizeof(something) bytes from byte 3, meaning I don’t want to read in byte 1 and 2 from the buffer. For example…

For some buffer, byte 1 = ‘a’, byte 2 = ‘b’, byte 3 = uint64_t variable. What I want to do is something like

1. set begin to byte 3
2. read in sizeof(uint64_t) bytes from buffer using memmove
  • 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-31T01:40:13+00:00Added an answer on May 31, 2026 at 1:40 am

    First, a bit of clarification. C array indexing starts at 0, not 1, so it’s more accurate to say that byte 0 is 'a' and byte 1 is 'b'. Second, your third byte, cannot contain a uint64_t variable, but index 2 may well be the beginning of a uint64_t object.

    No, there is no lseek equivalent for memmove() — because, unlike file operations, a call to memmove() must specify the starting point.

    And in this case, you might as well use memcpy() rather than memmove(). The only difference between them is that memmove() handles overlapping buffers correctly. Since your source and target are distinct objects, that’s not a concern. It’s not going to significantly affect your code’s speed, but anyone reading it won’t have to wonder why you chose to use memmove().

    Given:

    unsigned char buf[SOME_SIZE];
    uint64_t target;
    

    you can do something like this:

    memcpy(&target, buf+2, sizeof target);
    

    Note that I used sizeof target rather than sizeof (uint64_t). Either will work, but using sizeof target makes your code more resilient (less vulnerable to errors as you change it later on). If you decide to change the type of target, you don’t need to remember to change the type in the memcpy() call.

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

Sidebar

Related Questions

Doing a Socket.Receive(byte[]) will get the bytes in from the buffer, but if the
I have an application that uses the bluetooth to receive some data (bytes) from
i have locked my file from 0 to 5 bytes, and i write some
I have a simple code byte[] buffer = Encoding.UTF8.GetBytes(abracadabra); MemoryStream ms = new MemoryStream();
i have a char buffer[100] and i'm trying to use gdb to read the
I want my emacs buffer to have a different name than the file name.
When using a blocking TCP socket, I don't have to specify a buffer size.
I'm having an issue reading from a java input stream. I have a buffer
I have some python code that: Takes a BLOB from a database which is
I have a simple file transfer application, which transfers 4096 bytes per write from

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.