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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:15:22+00:00 2026-06-04T01:15:22+00:00

I have two network buffers defined as: buffer1 = bytearray(4096) buffer2 = bytearray(4096) Which

  • 0

I have two network buffers defined as:

buffer1 = bytearray(4096)
buffer2 = bytearray(4096)

Which is the fastest way to move the content from buffer2 to buffer1 without allocating extra memory?

The naive way would be to do:

for i in xrange(4096):
    buffer1[i] = buffer2[i]

Apparently if I do buffer1[:]=buffer2[:] python moves the content, but I’m not 100% sure of it because if I do:

a = bytearray([0,0,0])
b = bytearray([1,1])
a[:]=b[:]

then len(a)=2. What happens with the missing byte? Can anyone explain how this works or how to move data between buffers?

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-06-04T01:15:23+00:00Added an answer on June 4, 2026 at 1:15 am

    On my computer, the following

    buffer1[:] = buffer2
    

    copies a 4KB buffer in under 400 nanoseconds. In other words, you can do 2.5 million such copies per second.

    Is this fast enough for your needs?

    edit: If buffer2 is shorter than buffer1, and you want to copy its contents at a particular position in buffer1 without changing the rest of the target buffer, you can use the following:

    buffer1[pos:pos+len(buffer2)] = buffer2
    

    Similarly, you can use slicing on the right-hand side to only copy a portion of buffer2.

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

Sidebar

Related Questions

I'm trying to capture packets from two devices on my network. I have tcpdump
I have two content types called web jobs and network job. I need to
I have a machine with VmWare installed which added two extra network interfaces. The
Some specific situation: I have two Activities . FirstActivity loads data from network(~100 kb)
I have two Java applications in my network that talk to each other over
I have two folders, for arguments sake /Volumes/A and /Volumes/B. They are mounted network
I have two classes generated by LINQ2SQL both from the same table so they
I have a web service on IIS and I have two network interface cards.
I have a PC with two network cards connected to different networks (multi homed
if i have two IIS servers 5v on one network running winxp each hosting

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.